This is a creation in Article, where the information may have evolved or changed.
Gorose, the most coquettish go Orm, has a chain operation, out of the box, a minute to get started, such as eight big coquettish, let Golang operation database become a kind of enjoyment, mother can no longer see me to deal with the pain of data, let me one by one to explain the style of gorose
Coquettish one: Out of the box, a minute to get started
gorose.Open("xxxxxx这里是配置文件中的数据库配置")var db gorose.Databasedb.Query("select * from user") // 原生sql执行, 返回格式化后的结果
Coquettish Two: Chain operation, the charm of the gesture
db.Table("user").First()
Get sql:select * from user where id=1
Coquettish Three: Directly query the desired fields without declaring the field type beforehand
db.Table("user").Fields("id as uid,name").Where("id", ">", 1).Get()
Coquettish four: JSON return free toggle
gorose.JsonEncode(true)db.Table("user").First()
gorose.JsonEncode(false)db.Table("user").First()
Or
db.JsonEncode(false).Table("user").First()
Coquettish Five: One-click Transactions, fully automatic open/rollback/commit transactions, I just focus on the code itself
db.Transaction(func(){ db.Table("user").Data(map[string]interface{}{"name":"fizz"}).Insert() db.Table("user").Data(map[string]interface{}{"name":"fizz2"}).Where("id",1).Update()})
Coquettish Six: One-click Switch database connection, free to imagine between any database
db.Connect("mysql2").Table("goods").First()
Coquettish Seven: A lot of data is automatically chunked, I just need to focus on the code itself
All the data in the user table, every time I take out 100, and then finish, automatically fetch the next 100, continue processing, so repeatedly, until the data of the specified condition is processed
db.Table("user").Where("id","<",10000).Chunk(100, func(data []map[string]interface{}){ for _, item := range data { fmt.Println(item["name"]) }})
Coquettish Eight: Non-perceptual read-write separation, still focus only on the code itself, only need to set up in the configuration read library and write library can
More of a place of dominance
- Please look at Https://github.com/gohouse/gorose.
- Or click Join QQ Group: 470809220 slowly tease ~ ~ ~