Một mục mã nguồn mở trong kho dữ liệu GitHub của TopGit: astaxie/beedb, 704 sao, Go. beedb is a go ORM,support database/sql interface,pq/mysql/sqlite
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
:exclamation: IMPORTANT: Beedb is being deprecated in favor of Beego.orm :exclamation:
Beedb is an ORM for Go. It lets you map Go structs to tables in a database. It's intended to be very lightweight, doing very little beyond what you really want. For example, when fetching data, instead of re-inventing a query syntax, we just delegate your query to the underlying database, so you can write the "where" clause of your SQL statements directly. This allows you to have more flexibility while giving you a convenience layer. But beedb also has some smart defaults, for those times when complex queries aren't necessary.
Right now, it interfaces with Mysql/SQLite/PostgreSQL/DB2/MS ADODB/ODBC/Oracle. The goal however is to add support for other databases in the future, including maybe MongoDb or NoSQL?
Relationship-support is not implemented, for this we will recommend you to use Beego.orm.
All in all, it's not entirely ready for advanced use yet, but it's getting there.
Drivers for Go's sql package which support database/sql includes:
Mysql:github.com/ziutek/mymysql/godrv[*]
Mysql:github.com/Go-SQL-Driver/MySQL[*]
PostgreSQL:github.com/bmizerany/pq[*]
SQLite:github.com/mattn/go-sqlite3[*]
DB2: bitbucket.org/phiggins/go-db2-cli
MS ADODB: github.com/mattn/go-adodb[*]
ODBC: bitbucket.org/miquella/mgodbc[*]
Oracle: github.com/mattn/go-oci8
Drivers marked with a [*] are tested with Beedb
API Interface
wiki/API-Interface
Installing Beedb
go get github.com/astaxie/beedb
How do we use it?
Open a database link(may be will support ConnectionPool in the future)
type Userinfo struct {
Uid int `beedb:"PK" sql:"UID" tname:"USER_INFO"` //if the table's PrimaryKey is not "Id", use this tag
Username string `sql:"USERNAME"`
Departname string `sql:"DEPARTNAME"`
Created time.Time `sql:"CREATED"`
}
###Caution
The structs Name 'UserInfo' will turn into the table name 'USER_INFO', as defined by the tname tag.
If the key 'UserName' will turn into the select colum 'USERNAME' because of the sql tag.
saveone.Username = "Update Username"
saveone.Departname = "Update Departname"
saveone.Created = time.Now()
orm.Save(&saveone) //now saveone has the primarykey value it will update
Fetch a single object
var user Userinfo
orm.Where("uid=?", 27).Find(&user)
var user2 Userinfo
orm.Where(3).Find(&user2) // this is shorthand for the version above
var user3 Userinfo
orm.Where("name = ?", "john").Find(&user3) // more complex query
var user4 Userinfo
orm.Where("name = ? and age < ?", "john", 88).Find(&user4) // even more complex
Fetch multiple objects
var allusers []Userinfo
err := orm.Where("id > ?", "3").Limit(10,20).FindAll(&allusers) //Get id>3 limit 10 offset 20
var tenusers []Userinfo
err := orm.Where("id > ?", "3").Limit(10).FindAll(&tenusers) //Get id>3 limit 10 if omit offset the default is 0
var everyone []Userinfo
err := orm.FindAll(&everyone)
Find result as Map
//Original SQL Backinfo resultsSlice []map[string][]byte
//default PrimaryKey id
a, _ := orm.SetTable("userinfo").SetPK("uid").Where(2).Select("uid,username").FindMap()
Update with Map
t := make(map[string]interface{})
var j interface{}
j = "astaxie"
t["username"] = j
//update one
orm.SetTable("userinfo").SetPK("uid").Where(2).Update(t)
a, _ := orm.SetTable("userinfo").Join("LEFT", "userdeatail", "userinfo.uid=userdeatail.uid").Where("userinfo.uid=?", 1).Select("userinfo.uid,userinfo.username,userdeatail.profile").FindMap()
Group By And Having
a, _ := orm.SetTable("userinfo").GroupBy("username").Having("username='astaxie'").FindMap()
Nesting Models (inline)
type SQLModel struct {
Id int `beedb:"PK" sql:"id"`
Created time.Time `sql:"created"`
Modified time.Time `sql:"modified"`
}
type User struct {
SQLModel `sql:",inline"`
Name string `sql:"name" tname:"fn_group"`
Auth int `sql:"auth"`
}
// the SQL table has the columns: id, name, auth, created, modified
// They are marshalled and unmarshalled automatically because of the inline keyword
astaxie/beedb có 704 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/astaxie/beedb. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
astaxie/beedb có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho astaxie/beedb. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
astaxie/beedb còn đang phát triển không?
Commit gần nhất trên astaxie/beedb là 11.9 năm trước (theo timestamp GitHub). Repo có 162 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
astaxie/beedb là gì?
astaxie/beedb (astaxie/beedb) là dự án Go trên GitHub. Theo mô tả gốc: beedb is a go ORM,support database/sql interface,pq/mysql/sqlite
Đọc thêm về astaxie/beedb ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/astaxie/beedb là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về beedb?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về beedb.