Update README

This commit is contained in:
Jinzhu 2016-02-25 22:58:56 +08:00
parent ba8b2857ea
commit 9d0203847c
6 changed files with 46 additions and 1412 deletions

1411
README.md

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
# GORM Guides
# GORM
The fantastic ORM library for Golang, aims to be developer friendly.
@ -28,6 +28,35 @@ The fantastic ORM library for Golang, aims to be developer friendly.
go get -u github.com/jinzhu/gorm
```
## Basic Usage
```go
type Product struct {
gorm.Model
Code string
Price uint
}
var db *gorm.DB
func init() {
var err error
db, err = gorm.Open("sqlite", "test.db")
}
func main() {
db.Create(&Product{Code: "L1212", Price: 1000})
var product Product
db.First(&product, 1) // find product with id 1
db.First(&product, "code = ?", "L1212") // find product with code l1212
db.Model(&product).Update("Price", 2000) // update product's price to 2000
db.Delete(&product) // delete product
}
```
# Author
**jinzhu**

10
doc/advanced/advanced.md Normal file
View File

@ -0,0 +1,10 @@
# Advanced Usage
{% for section in book.chapters["advanced/advanced.md"].sections %}
* [**{{section.name}}**](../{{section.path}})
{% if section["sections"] %}{% for subsection in section.sections %}
* [**{{ subsection.name }}**]({{ subsection.path }})
{% endfor %}{% endif %}
{% endfor %}

View File

@ -20,7 +20,8 @@ tx.Commit()
```
### A Specific Example
```
```go
func CreateAnimals(db *gorm.DB) err {
tx := db.Begin()
// Note the use of tx as the database handle once you are within a transaction

View File

@ -2,7 +2,7 @@
"title": "GORM Guide",
"plugins": [
"prism", "-highlight", "collapsible-menu", "toc",
"github", "anchors", "edit-link"
"github", "edit-link"
],
"pluginsConfig": {
"toc": {

View File

@ -73,3 +73,4 @@ func (user *User) BeforeCreate(scope *gorm.Scope) error {
// Add extra SQL option for inserting SQL
db.Set("gorm:insert_option", "ON CONFLICT").Create(&product)
// INSERT INTO products (name, code) VALUES ("name", "code") ON CONFLICT;
```