aacanakin / qb
- понедельник, 16 мая 2016 г. в 03:12:59
Go
The database toolkit for go
This project is currently pre 1.
It can currently have potential bugs. Currently, there are no tests having concurrency race condition tests. It can currently crash especially in concurrency. Moreover, before 1.x releases, each major release could break backwards compatibility.
qb is a database toolkit for easier db usage in go. It is inspired from python's most favorite orm sqlalchemy. qb is an orm as well as a query builder. It is quite modular in case of using just expression api and query building stuff.
The documentation is hosted in readme.io which has great support for markdown docs. Currently, the docs is about 80% - 90% complete. The doc files will be added to this repo soon. Moreover, you can check the godoc from here. Contributions & Feedbacks in docs are welcome.
Installation with glide;
glide get github.com/aacanakin/qb
Installation using go get;
go get -u github.com/aacanakin/qb
If you want to install test dependencies then;
go get -u -t github.com/aacanakin/qb
package main
import (
"fmt"
"github.com/aacanakin/qb"
"github.com/nu7hatch/gouuid"
)
type User struct {
ID string `qb:"type:uuid; constraints:primary_key"`
Email string `qb:"constraints:unique, notnull"`
FullName string `qb:"constraints:notnull"`
Bio string `qb:"type:text; constraints:null"`
}
func main() {
db, err := qb.New("postgres", "user=postgres dbname=qb_test sslmode=disable")
if err != nil {
panic(err)
}
defer db.Close()
// add table to metadata
db.Metadata().Add(User{})
// create all tables registered to metadata
db.Metadata().CreateAll()
userID, _ := uuid.NewV4()
db.Add(&User{
ID: userID.String(),
Email: "robert@de-niro.com",
FullName: "Robert De Niro",
})
err = db.Commit() // insert user
if err != nil {
fmt.Println(err)
return
}
var user User
db.Find(&User{ID: userID.String()}).One(&user)
fmt.Println("id", user.ID)
fmt.Println("email", user.Email)
fmt.Println("full_name", user.FullName)
db.Metadata().DropAll() // drops all tables
}