{"_id":"57531435be31940e0035ad99","project":"56e5982f9191742000ef204a","category":{"_id":"57531435be31940e0035ad97","__v":0,"project":"56e5982f9191742000ef204a","version":"57531435be31940e0035ad96","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-03-13T16:41:20.277Z","from_sync":false,"order":0,"slug":"documentation","title":"Getting Started"},"version":{"_id":"57531435be31940e0035ad96","project":"56e5982f9191742000ef204a","__v":3,"createdAt":"2016-06-04T17:47:33.623Z","releaseDate":"2016-06-04T17:47:33.623Z","categories":["57531435be31940e0035ad97","57531435be31940e0035ad98","57531652d8fe070e00258a51","576c609fba92910e0099ad3f"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.2.0","version":"0.2"},"user":"543466ea0e8e2b0e00341818","__v":13,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-04-18T08:17:23.977Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"qb is a database toolkit for easier implementation for db heavy apps in go. The aim is to build a lightweight architecture on top of [sqlx](https://github.com/jmoiron/sqlx) library for painless db implementation in go. It is inspired from python's most favorite sql package called [sqlalchemy](http://www.sqlalchemy.org/)\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Features\"\n}\n[/block]\n- Support for postgres(9.5.+), mysql, mariadb & sqlite\n- An expression api which can build almost any common sql queries and table ddls\n- A transactional session api implemented on top of query builder that have commonly used db queries such as Find(), All(), etc.\n- A metadata api where tables can be generated and created from structs\n- A struct to table mapper with use of tagging\n- A query to struct mapper with use of sqlx library\n- Foreign key reference definitions with use of tagging\n- Single & composite column indices with use of tagging\n- Relationships (coming soon..)\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Raison d'être\"\n}\n[/block]\nThe reason this package is being developed is mainly because of my personal curiosity. It is currently a hobby project of mine. However, there are more several reasons. I have played with most of the ormish libraries in go. At the time, neither of them were complete and there is a quite well [post](http://www.hydrogen18.com/blog/golang-orms-and-why-im-still-not-using-one.html) about that which resonates the point.\n\nMoreover, there is this tweet I had posted about the go db/orm community;\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/jDRmzUrBTsm95UDi1800_Screen%20Shot%202016-03-08%20at%2012.05.18%20AM.png\",\n        \"Screen Shot 2016-03-08 at 12.05.18 AM.png\",\n        \"1286\",\n        \"710\",\n        \"#333237\",\n        \"\"\n      ],\n      \"sizing\": \"smart\",\n      \"border\": true\n    }\n  ]\n}\n[/block]\nFrom my perspective, I think qb solves most of the problems I'm suffering when using an orm in go and hopefully, it would be useful to anyone that has the similar problems with me.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Installation\"\n}\n[/block]\nTo install qb, a simple go get would do the trick;\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"go get -v -u github.com/aacanakin/qb\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nTo get the test dependencies add a -t flag;\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"go get -v -u -t github.com/aacanakin/qb\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nMoreover, [glide](https://glide.sh/) is also supported;\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"glide get github.com/aacanakin/qb\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Quick Start\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"package main\\n\\nimport (\\n    \\\"fmt\\\"\\n    \\\"github.com/aacanakin/qb\\\"\\n    \\\"github.com/nu7hatch/gouuid\\\"\\n)\\n\\ntype User struct {\\n    ID       string `qb:\\\"type:uuid; constraints:primary_key\\\"`\\n    Email    string `qb:\\\"constraints:unique, notnull\\\"`\\n    FullName string `qb:\\\"constraints:notnull\\\"`\\n    Bio      string `qb:\\\"type:text; constraints:null\\\"`\\n}\\n\\nfunc main() {\\n\\n    db, err := qb.New(\\\"postgres\\\", \\\"user=postgres dbname=qb_test sslmode=disable\\\")\\n    if err != nil {\\n        panic(err)\\n    }\\n\\n    defer db.Close()\\n\\n    // add table to metadata\\n    db.AddTable(User{})\\n\\n    // create all tables registered to metadata\\n    err := db.CreateAll()\\n    if err != nil {\\n      panic(err)\\n    }\\n\\n    userID, _ := uuid.NewV4()\\n    db.Add(&User{\\n        ID:       userID.String(),\\n        Email:    \\\"robert:::at:::de-niro.com\\\",\\n        FullName: \\\"Robert De Niro\\\",\\n    })\\n\\n    err = db.Commit() // insert user\\n    fmt.Println(err)\\n\\n    var user User\\n    db.Find(&User{ID: userID.String()}).First(&user)\\n\\n    fmt.Println(\\\"id\\\", user.ID)\\n    fmt.Println(\\\"email\\\", user.Email)\\n    fmt.Println(\\\"full_name\\\", user.FullName)\\n\\n    db.Metadata().DropAll() // drops all tables\\n\\n}\",\n      \"language\": \"go\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"introduction","type":"basic","title":"Introduction"}
qb is a database toolkit for easier implementation for db heavy apps in go. The aim is to build a lightweight architecture on top of [sqlx](https://github.com/jmoiron/sqlx) library for painless db implementation in go. It is inspired from python's most favorite sql package called [sqlalchemy](http://www.sqlalchemy.org/) [block:api-header] { "type": "basic", "title": "Features" } [/block] - Support for postgres(9.5.+), mysql, mariadb & sqlite - An expression api which can build almost any common sql queries and table ddls - A transactional session api implemented on top of query builder that have commonly used db queries such as Find(), All(), etc. - A metadata api where tables can be generated and created from structs - A struct to table mapper with use of tagging - A query to struct mapper with use of sqlx library - Foreign key reference definitions with use of tagging - Single & composite column indices with use of tagging - Relationships (coming soon..) [block:api-header] { "type": "basic", "title": "Raison d'être" } [/block] The reason this package is being developed is mainly because of my personal curiosity. It is currently a hobby project of mine. However, there are more several reasons. I have played with most of the ormish libraries in go. At the time, neither of them were complete and there is a quite well [post](http://www.hydrogen18.com/blog/golang-orms-and-why-im-still-not-using-one.html) about that which resonates the point. Moreover, there is this tweet I had posted about the go db/orm community; [block:image] { "images": [ { "image": [ "https://files.readme.io/jDRmzUrBTsm95UDi1800_Screen%20Shot%202016-03-08%20at%2012.05.18%20AM.png", "Screen Shot 2016-03-08 at 12.05.18 AM.png", "1286", "710", "#333237", "" ], "sizing": "smart", "border": true } ] } [/block] From my perspective, I think qb solves most of the problems I'm suffering when using an orm in go and hopefully, it would be useful to anyone that has the similar problems with me. [block:api-header] { "type": "basic", "title": "Installation" } [/block] To install qb, a simple go get would do the trick; [block:code] { "codes": [ { "code": "go get -v -u github.com/aacanakin/qb", "language": "shell" } ] } [/block] To get the test dependencies add a -t flag; [block:code] { "codes": [ { "code": "go get -v -u -t github.com/aacanakin/qb", "language": "shell" } ] } [/block] Moreover, [glide](https://glide.sh/) is also supported; [block:code] { "codes": [ { "code": "glide get github.com/aacanakin/qb", "language": "shell" } ] } [/block] [block:api-header] { "type": "basic", "title": "Quick Start" } [/block] [block:code] { "codes": [ { "code": "package main\n\nimport (\n \"fmt\"\n \"github.com/aacanakin/qb\"\n \"github.com/nu7hatch/gouuid\"\n)\n\ntype User struct {\n ID string `qb:\"type:uuid; constraints:primary_key\"`\n Email string `qb:\"constraints:unique, notnull\"`\n FullName string `qb:\"constraints:notnull\"`\n Bio string `qb:\"type:text; constraints:null\"`\n}\n\nfunc main() {\n\n db, err := qb.New(\"postgres\", \"user=postgres dbname=qb_test sslmode=disable\")\n if err != nil {\n panic(err)\n }\n\n defer db.Close()\n\n // add table to metadata\n db.AddTable(User{})\n\n // create all tables registered to metadata\n err := db.CreateAll()\n if err != nil {\n panic(err)\n }\n\n userID, _ := uuid.NewV4()\n db.Add(&User{\n ID: userID.String(),\n Email: \"robert@de-niro.com\",\n FullName: \"Robert De Niro\",\n })\n\n err = db.Commit() // insert user\n fmt.Println(err)\n\n var user User\n db.Find(&User{ID: userID.String()}).First(&user)\n\n fmt.Println(\"id\", user.ID)\n fmt.Println(\"email\", user.Email)\n fmt.Println(\"full_name\", user.FullName)\n\n db.Metadata().DropAll() // drops all tables\n\n}", "language": "go" } ] } [/block]