forked from mirror/gorm
README
This commit is contained in:
parent
a135087af4
commit
e2927e1ec5
10
README.md
10
README.md
|
@ -27,7 +27,7 @@ Yet Another ORM library for Go, aims for developer friendly
|
||||||
```go
|
```go
|
||||||
db, err = Open("postgres", "user=gorm dbname=gorm sslmode=disable")
|
db, err = Open("postgres", "user=gorm dbname=gorm sslmode=disable")
|
||||||
|
|
||||||
// Gorm is goroutines friendly, so you can create a global variable to keep the connection and use it everywhere
|
// Gorm is goroutines friendly, so you can create a global variable to keep the connection and use it everywhere like this
|
||||||
|
|
||||||
var DB gorm.DB
|
var DB gorm.DB
|
||||||
|
|
||||||
|
@ -50,9 +50,10 @@ type User struct { // TableName: `users`, gorm will pluralize struc
|
||||||
Birthday time.Time // Time
|
Birthday time.Time // Time
|
||||||
Age int64
|
Age int64
|
||||||
Name string
|
Name string
|
||||||
CreatedAt time.Time // CreatedAt: Time of record is created, will be insert automatically
|
CreatedAt time.Time // Time of record is created, will be insert automatically
|
||||||
UpdatedAt time.Time // UpdatedAt: Time of record is updated, will be updated automatically
|
UpdatedAt time.Time // Time of record is updated, will be updated automatically
|
||||||
DeletedAt time.Time // DeletedAt: Time of record is deleted, refer Soft Delete for more
|
DeletedAt time.Time // Time of record is deleted, refer Soft Delete for more
|
||||||
|
|
||||||
Email []Email // Embedded structs
|
Email []Email // Embedded structs
|
||||||
BillingAddress Address // Embedded struct
|
BillingAddress Address // Embedded struct
|
||||||
BillingAddressId int64 // Embedded struct BillingAddress's foreign key
|
BillingAddressId int64 // Embedded struct BillingAddress's foreign key
|
||||||
|
@ -348,6 +349,7 @@ db.Where(User{Name: "noexisting_user"}).Attrs("age", 20).FirstOrInit(&user)
|
||||||
db.Where(User{Name: "Jinzhu"}).Attrs(User{Age: 30}).FirstOrInit(&user)
|
db.Where(User{Name: "Jinzhu"}).Attrs(User{Age: 30}).FirstOrInit(&user)
|
||||||
//// SELECT * FROM USERS WHERE name = jinzhu';
|
//// SELECT * FROM USERS WHERE name = jinzhu';
|
||||||
//// User{Id: 111, Name: "Jinzhu", Age: 20}
|
//// User{Id: 111, Name: "Jinzhu", Age: 20}
|
||||||
|
```
|
||||||
|
|
||||||
### FirstOrInit With Assign
|
### FirstOrInit With Assign
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue