當前較爲主流/活躍的orm有gorm、xorm、gorose等html
文檔mysql
鏈式apigit
has, err := engine.Where("name = ?", name).Desc("id").Get(&user) err := engine.Where(builder.NotIn("a", 1, 2).And(builder.In("b", "c", "d", "e"))).Find(&users)
支持批量查詢處理github
// 每次處理100條 // SELECT * FROM user Limit 0, 100 // SELECT * FROM user Limit 101, 100 err := engine.BufferSize(100).Iterate(&User{Name:name}, func(idx int, bean interface{}) error { user := bean.(*User) return nil })
dataSourceNameSlice := []string{masterDataSourceName, slave1DataSourceName, slave2DataSourceName} engineGroup, err := xorm.NewEngineGroup(driverName, dataSourceNameSlice)
文檔golang
鏈式apisql
tx := db.Where("name = ?", "jinzhu").Where("age = ?", 20).Find(&users)
查詢操做數據庫
// Get first record, order by primary key db.First(&user) //// SELECT * FROM users ORDER BY id LIMIT 1; // plain sql db.Where("name = ? AND age >= ?", "jinzhu", "22").Find(&users) // map db.Where(&User{Name: "jinzhu", Age: 20}).First(&user) //// SELECT * FROM users WHERE name = "jinzhu" AND age = 20 LIMIT 1;
文檔api
事務性緩存
User.Fields("id, name").Where("id",">",2).Chunk(2, func(data []map[string]interface{}) { // for _,item := range data { // fmt.Println(item) // } fmt.Println(data) })
同時支持nosql和sql的orm很少,這是其中之一 (另外一個是beedb,已經四年沒有更新了). upper/db對多種數據庫進行封裝,提供統一的接口進行CRUD.oracle
文檔
sess, err := postgresql.Open(settings) if err != nil { log.Fatalf("db.Open(): %q\n", err) } defer sess.Close() var books []Book err = sess.Collection("books").Find().All(&books)
類似性
差別