forked from mirror/gorm
Update README
This commit is contained in:
parent
a81b9f3950
commit
c412729570
17
README.md
17
README.md
|
@ -2,6 +2,18 @@
|
||||||
|
|
||||||
Yet Another ORM library for Go, aims for developer friendly
|
Yet Another ORM library for Go, aims for developer friendly
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
* CURD
|
||||||
|
* Chainable API
|
||||||
|
* Before/After Create/Save/Update/Delete Callbacks
|
||||||
|
* Order/Select/Limit/Offset Support
|
||||||
|
* Automatically CreatedAt, UpdatedAt
|
||||||
|
* Create table from struct
|
||||||
|
* Prevent SQL Injection
|
||||||
|
* Goroutines friendly
|
||||||
|
* Database Pool
|
||||||
|
|
||||||
## Basic Usage
|
## Basic Usage
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
@ -16,8 +28,11 @@ type User struct {
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set database pool
|
||||||
|
db.SetPool(10)
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
user = User{Name: "jinzhu", Age: 18, Birthday: time.Now())
|
user = User{Name: "jinzhu", Age: 18, Birthday: time.Now()}
|
||||||
db.Save(&user)
|
db.Save(&user)
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
|
|
4
main.go
4
main.go
|
@ -17,6 +17,10 @@ func Open(driver, source string) (db DB, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DB) SetPool(n int) {
|
||||||
|
s.Db.SetMaxIdleConns(n)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DB) buildORM() *Chain {
|
func (s *DB) buildORM() *Chain {
|
||||||
return &Chain{db: s.Db, driver: s.Driver}
|
return &Chain{db: s.Db, driver: s.Driver}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
db, _ = Open("postgres", "user=gorm dbname=gorm sslmode=disable")
|
db, _ = Open("postgres", "user=gorm dbname=gorm sslmode=disable")
|
||||||
|
db.SetPool(10)
|
||||||
|
|
||||||
db.Exec("drop table users;")
|
db.Exec("drop table users;")
|
||||||
db.Exec("drop table products;")
|
db.Exec("drop table products;")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue