sqlbuilder

Go 开源说第二期:GORM 剖析与最佳实践

試著忘記壹切 提交于 2021-01-01 18:41:27
写在前面 随着Go在中国越来越多的应用场景,我们中国的Gopher开发的开源项目也越来越多,目前在github上面有大量的Go写的开源项目,但是很多时候一个好的项目让别人获知,同时让大家了解背后的设计设计原理,其实是很困难的一件事情。 基于这样的背景,我们GoCN社区推出这个《Go 开源说》,每两周会播出一期。希望通过这样的平台帮助到我们开源的作者,有一个平台去推广我们的开源项目,第二说说背后的设计原理和理念,产品优越性等。第三让我们用户可以了解到更多好玩有用的项目,避免自己造轮子重复发明,当然也希望通过这些分享让大家学习到每一个开源项目背后的设计理念,拥抱开源,做出自己的产品。 —— Asta 本期开源先锋 张金柱 https://github.com/jinzhu 就职于字节跳动基础架构语言团队 目前从事字节跳动的性能分析、优化及 GORM 开发相关工作 关于 GORM https://github.com/go-gorm/gorm 设计简洁、功能强大、自由扩展的全功能 ORM 设计原则 API 精简、测试优先、最小惊讶、灵活扩展、无依赖 可信赖 功能完善 关联:一对一、一对多、单表自关联、多态关联;Preload、Joins 预加载;关联模式 事务:嵌套事务, Save Point Hooks、Callbacks 自由扩展 多数据库、读写分离、Prometheus

zombodb  query dsl

时光毁灭记忆、已成空白 提交于 2020-05-03 20:35:45
zombodb query dsl 是为了简化es 查询的处理,同时可以兼容基本上所有的es 操作 一个简单的查询,查询任何字段包含cats 以及dogs 的 SELECT * FROM table WHERE table ==> <cats and dogs query here> zombodb 会将这个sql 查询处理,转化为 zdbquery ,实际上我们可以通过查询分析也看出来 zombodb 查询语法 支持类似google 搜索的模式,实现是基于es 的查询语法 一个简单查询 SELECT * FROM table WHERE table ==> '+cats +dogs'; SELECT * FROM table WHERE table ==> 'cats AND dogs'; 实际的处理 SELECT '+cats +dogs'::zdbquery::json; json ------------------------------------------ {"query_string":{"query":"+cats +dogs"}} SELECT 'cats AND dogs'::zdbquery::json; json -------------------------------------------- {"query_string":{"query":

EF中使用事务

喜夏-厌秋 提交于 2020-04-28 01:00:32
1.EF中的默认的事务 默认情况下,当我们执行一个SaveChanges()方法时就会新建了一个事务,然后将context中的CUD操作都在这个事务中进行。Context中有多个SaveChanges()时,每一个SaveChanges()都会执行一个单独的事务。一个栗子: using ( var context = new SchoolContext()) { context.Database.Log = Console.Write; var standard = context.Standards.Add( new Standard() { StandardName = " 1st Grade " }); context.Students.Add( new Student() { FirstName = " Rama " , StandardId = standard.StandardId }); context.SaveChanges(); context.Courses.Add( new Course() { CourseName = " Computer Science " }); context.SaveChanges(); } 上边的代码执行结果如下: 从上边的栗子我们可以清楚地看到每个SaveChanges()方法都开启了一个事务。这时有一个问题

mybatis-sql builder class

有些话、适合烂在心里 提交于 2020-03-02 07:23:22
在拼接sql的时候,经常遇到字符串写的太长无法辨别的情况 String sql = "SELECT P.ID, P.USERNAME, P.PASSWORD, P.FULL_NAME, " "P.LAST_NAME,P.CREATED_ON, P.UPDATED_ON " + "FROM PERSON P, ACCOUNT A " + "INNER JOIN DEPARTMENT D on D.ID = P.DEPARTMENT_ID " + "INNER JOIN COMPANY C on D.COMPANY_ID = C.ID " + "WHERE (P.ID = A.ID AND P.FIRST_NAME like ?) " + "OR (P.LAST_NAME like ?) " + "GROUP BY P.ID " + "HAVING (P.LAST_NAME like ?) " + "OR (P.FIRST_NAME like ?) " + "ORDER BY P.ID, P.FULL_NAME"; mybatis3中通过SQLclass使得代码更整洁 private String selectPersonSql() { return new SQL() {{ SELECT("P.ID, P.USERNAME, P.PASSWORD, P.FULL_NAME");

Get raw sql statement with DbExtensions SqlBuilder

别等时光非礼了梦想. 提交于 2020-01-17 07:52:27
问题 I'm using the SqlBuilder to build a dynamic sql statement where the SELECT and WHERE clauses vary. The query is built like this: SqlBuilder sb = new SqlBuilder(); sb.SELECT("id, name"); sb.FROM("products"); sb.WHERE("name LIKE {0}", new object[] { "a%" }); Once I've got the SqlBuilder ready, I would like to get the raw sql statement. However, the ToString() method returns a string which might look like this: SELECT id, name FROM products WHERE name LIKE {0} I need the raw sql with the

Question mark placeholder

人盡茶涼 提交于 2020-01-02 23:08:16
问题 How can I replace all '?' the variables? Something like: $name = 'test' ; $lname = 'lastTest'; $id = 1 ; ->where ( 'customers.name = ? and customers.lastname = ? and customers.id = ?' , $name , $lname , $id ) ; output: customers.name = 'test' and customers.lastname = 'lastTest' and customers.id = 1 Any ideas? 回答1: I really think you should use a library like PDO, but here is a solution nonetheless: public function where($query) { $args = func_get_args(); array_shift($args); $query = preg

How to use SqlBuilder

限于喜欢 提交于 2019-12-23 09:06:07
问题 This SqlBuilder: var builder = new SqlBuilder(); var sql = builder.AddTemplate( /*... Intensely dumb question but, how do I use this? I know it's in Dapper.Contrib , but that using statement isn't enough. What references or other using statements do I need to add? 回答1: This question appears in the dapper tutorial page, so I'm updating the answer. In version 1.6, SqlBuilder is in the namespace Dapper . And it is included in the nuget package Dapper.SqlBuilder. This is an example of how it