diff --git a/README.md b/README.md index 9034cfd0..feebcb51 100644 --- a/README.md +++ b/README.md @@ -32,34 +32,34 @@ Yet Another ORM library for Go, aims for developer friendly ```go type User struct { - Id int64 - Birthday time.Time - Age int64 - Name string `sql:"size:255"` - CreatedAt time.Time - UpdatedAt time.Time - DeletedAt time.Time + Id int64 + Birthday time.Time + Age int64 + Name string `sql:"size:255"` + CreatedAt time.Time + UpdatedAt time.Time + DeletedAt time.Time - Emails []Email // Embedded structs - BillingAddress Address // Embedded struct - BillingAddressId sql.NullInt64 // BillingAddress's foreign key - ShippingAddress Address // Another Embedded struct with same type - ShippingAddressId int64 // ShippingAddress's foreign key - IgnoreMe int64 `sql:"-"` // Ignore this field + Emails []Email // Embedded structs + BillingAddress Address // Embedded struct + BillingAddressId sql.NullInt64 // BillingAddress's foreign key + ShippingAddress Address // Another Embedded struct with same type + ShippingAddressId int64 // ShippingAddress's foreign key + IgnoreMe int64 `sql:"-"` // Ignore this field } type Email struct { - Id int64 - UserId int64 // Foreign key for User - Email string `sql:"type:varchar(100);"` // Set this field's type - Subscribed bool + Id int64 + UserId int64 // Foreign key for User + Email string `sql:"type:varchar(100);"` // Set this field's type + Subscribed bool } type Address struct { - Id int64 - Address1 string `sql:"not null;unique"` // Set this field as not nullable and unique in database - Address2 string `sql:"type:varchar(100);unique"` - Post sql.NullString `sql:not null` + Id int64 + Address1 string `sql:"not null;unique"` // Set this field as not nullable and unique in database + Address2 string `sql:"type:varchar(100);unique"` + 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... } ``` @@ -155,10 +155,10 @@ Refer [Query With Related](#query-with-related) for how to find associations ```go user := User{ - Name: "jinzhu", - BillingAddress: Address{Address1: "Billing Address - Address 1"}, - ShippingAddress: Address{Address1: "Shipping Address - Address 1"}, - Emails: []Email{{Email: "jinzhu@example.com"}, {Email: "jinzhu-2@example@example.com"}}, + Name: "jinzhu", + BillingAddress: Address{Address1: "Billing Address - Address 1"}, + ShippingAddress: Address{Address1: "Shipping Address - Address 1"}, + Emails: []Email{{Email: "jinzhu@example.com"}, {Email: "jinzhu-2@example@example.com"}}, } db.Save(&user) @@ -687,7 +687,7 @@ type Cart struct { } func (c Cart) TableName() string { - return "shopping_cart" + return "shopping_cart" } func (u User) TableName() string {