forked from mirror/gorm
Update README
This commit is contained in:
parent
ba8b2857ea
commit
9d0203847c
|
@ -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**
|
||||
|
|
|
@ -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 %}
|
||||
|
||||
|
|
@ -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
|
|
@ -2,7 +2,7 @@
|
|||
"title": "GORM Guide",
|
||||
"plugins": [
|
||||
"prism", "-highlight", "collapsible-menu", "toc",
|
||||
"github", "anchors", "edit-link"
|
||||
"github", "edit-link"
|
||||
],
|
||||
"pluginsConfig": {
|
||||
"toc": {
|
||||
|
|
|
@ -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;
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue