gorm/documents
Andy Ruland 3836f5441e Added working syntax to ignore field
Replaced non-working `gorm:"-"` syntax with `sql:"-"` to ignore a field in a struct
2016-06-12 07:08:32 +04:00
..
2016-02-28 18:07:46 +08:00
2016-02-28 18:07:46 +08:00
2016-03-08 11:59:56 +08:00
2016-03-08 09:35:39 +08:00
2016-03-09 07:36:34 +08:00
2016-03-08 09:51:34 +08:00
2016-03-08 12:14:16 +08:00
2016-03-23 07:34:22 +08:00
2016-03-09 13:01:22 +00:00
2016-02-28 18:07:46 +08:00
2016-06-12 07:08:32 +04:00
2016-03-08 23:15:08 +08:00
2016-04-29 12:00:44 -04:00
2016-03-08 19:41:04 -05:00

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

go get -u github.com/jinzhu/gorm

Upgrading To V1.0

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")
  }

  // Migrate the schema
  db.AutoMigrate(&Product{})
  
  // Create
  db.Create(&Product{Code: "L1212", Price: 1000})

  // Read
  var product Product
  db.First(&product, 1) // find product with id 1
  db.First(&product, "code = ?", "L1212") // find product with code l1212

  // Update - update product's price to 2000
  db.Model(&product).Update("Price", 2000)

  // Delete - delete product
  db.Delete(&product)
}

Author

jinzhu

Contributors

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

License

Released under the MIT License.