Gorose-'s most popular go orm, chained operation, out-of-the-box, one-minute start-up, let Golang operation database become a kind of enjoyment

Source: Internet
Author: User
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

    • Specify JSON
gorose.JsonEncode(true)db.Table("user").First()
    • Cancel JSON return
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 ~ ~ ~
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.