The fantastic ORM library for Golang, aims to be developer friendly.
Overview
- Full-Featured ORM (almost)
- Associations (Has One, Has Many, Belongs To, Many To Many, Polymorphism)
- Hooks (Before/After Create/Save/Update/Delete/Find)
- Preloading (eager loading)
- Transactions
- Composite Primary Key
- SQL Builder
- Auto Migrations
- Logger
- Extendable, write Plugins based on GORM callbacks
- Every feature comes with tests
- Developer Friendly
Install
go get -u github.com/jinzhu/gorm
|
Quick Start
package main
import ( "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/sqlite" )
type Product struct { gorm.Model Code string Price uint }
func main() { db, err := gorm.Open("sqlite3", "test.db") if err != nil { panic("failed to connect database") } defer db.Close()
db.AutoMigrate(&Product{})
db.Create(&Product{Code: "L1212", Price: 1000})
var product Product db.First(&product, 1) db.First(&product, "code = ?", "L1212")
db.Model(&product).Update("Price", 2000)
db.Delete(&product) }
|