GORM

The fantastic ORM library for Golang, aims to be developer friendly.

Join the chat at https://gitter.im/jinzhu/gorm
wercker status
GoDoc

Overview

  • Full-Featured ORM (almost)
  • Associations (Has One, Has Many, Belongs To, Many To Many, Polymorphism)
  • Callbacks (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

  1. go get -u github.com/jinzhu/gorm

Upgrading To V1.0

Quick Start

  1. package main
  2. import (
  3. "github.com/jinzhu/gorm"
  4. _ "github.com/jinzhu/gorm/dialects/sqlite"
  5. )
  6. type Product struct {
  7. gorm.Model
  8. Code string
  9. Price uint
  10. }
  11. func main() {
  12. db, err := gorm.Open("sqlite3", "test.db")
  13. if err != nil {
  14. panic("failed to connect database")
  15. }
  16. defer db.Close()
  17. // Migrate the schema
  18. db.AutoMigrate(&Product{})
  19. // Create
  20. db.Create(&Product{Code: "L1212", Price: 1000})
  21. // Read
  22. var product Product
  23. db.First(&product, 1) // find product with id 1
  24. db.First(&product, "code = ?", "L1212") // find product with code l1212
  25. // Update - update product's price to 2000
  26. db.Model(&product).Update("Price", 2000)
  27. // Delete - delete product
  28. db.Delete(&product)
  29. }

Contributors

https://github.com/jinzhu/gorm/graphs/contributors

Supporting the project

http://patreon.com/jinzhu

Author

jinzhu

License

Released under the MIT License.