forked from mirror/gorm
Convert Tab to Spaces in README
This commit is contained in:
parent
0e2bef7006
commit
81a44f0283
52
README.md
52
README.md
|
@ -32,34 +32,34 @@ Yet Another ORM library for Go, aims for developer friendly
|
||||||
|
|
||||||
```go
|
```go
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
Birthday time.Time
|
Birthday time.Time
|
||||||
Age int64
|
Age int64
|
||||||
Name string `sql:"size:255"`
|
Name string `sql:"size:255"`
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
DeletedAt time.Time
|
DeletedAt time.Time
|
||||||
|
|
||||||
Emails []Email // Embedded structs
|
Emails []Email // Embedded structs
|
||||||
BillingAddress Address // Embedded struct
|
BillingAddress Address // Embedded struct
|
||||||
BillingAddressId sql.NullInt64 // BillingAddress's foreign key
|
BillingAddressId sql.NullInt64 // BillingAddress's foreign key
|
||||||
ShippingAddress Address // Another Embedded struct with same type
|
ShippingAddress Address // Another Embedded struct with same type
|
||||||
ShippingAddressId int64 // ShippingAddress's foreign key
|
ShippingAddressId int64 // ShippingAddress's foreign key
|
||||||
IgnoreMe int64 `sql:"-"` // Ignore this field
|
IgnoreMe int64 `sql:"-"` // Ignore this field
|
||||||
}
|
}
|
||||||
|
|
||||||
type Email struct {
|
type Email struct {
|
||||||
Id int64
|
Id int64
|
||||||
UserId int64 // Foreign key for User
|
UserId int64 // Foreign key for User
|
||||||
Email string `sql:"type:varchar(100);"` // Set this field's type
|
Email string `sql:"type:varchar(100);"` // Set this field's type
|
||||||
Subscribed bool
|
Subscribed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Address struct {
|
type Address struct {
|
||||||
Id int64
|
Id int64
|
||||||
Address1 string `sql:"not null;unique"` // Set this field as not nullable and unique in database
|
Address1 string `sql:"not null;unique"` // Set this field as not nullable and unique in database
|
||||||
Address2 string `sql:"type:varchar(100);unique"`
|
Address2 string `sql:"type:varchar(100);unique"`
|
||||||
Post sql.NullString `sql:not null`
|
Post sql.NullString `sql:not null`
|
||||||
// FYI, "NOT NULL" will only works well with NullXXX Scanner, because golang will initalize a default value for most type...
|
// FYI, "NOT NULL" will only works well with NullXXX Scanner, because golang will initalize a default value for most type...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -155,10 +155,10 @@ Refer [Query With Related](#query-with-related) for how to find associations
|
||||||
|
|
||||||
```go
|
```go
|
||||||
user := User{
|
user := User{
|
||||||
Name: "jinzhu",
|
Name: "jinzhu",
|
||||||
BillingAddress: Address{Address1: "Billing Address - Address 1"},
|
BillingAddress: Address{Address1: "Billing Address - Address 1"},
|
||||||
ShippingAddress: Address{Address1: "Shipping Address - Address 1"},
|
ShippingAddress: Address{Address1: "Shipping Address - Address 1"},
|
||||||
Emails: []Email{{Email: "jinzhu@example.com"}, {Email: "jinzhu-2@example@example.com"}},
|
Emails: []Email{{Email: "jinzhu@example.com"}, {Email: "jinzhu-2@example@example.com"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Save(&user)
|
db.Save(&user)
|
||||||
|
@ -687,7 +687,7 @@ type Cart struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Cart) TableName() string {
|
func (c Cart) TableName() string {
|
||||||
return "shopping_cart"
|
return "shopping_cart"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) TableName() string {
|
func (u User) TableName() string {
|
||||||
|
|
Loading…
Reference in New Issue