a little change of reademe

This commit is contained in:
Lunny Xiao 2013-05-03 15:41:50 +08:00
parent 202c8a68a4
commit 95927253d4
1 changed files with 9 additions and 7 deletions

View File

@ -22,13 +22,13 @@ SQLite:[github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3)
### Quick Start ### Quick Start
1. Create an database engine (for example: mysql) 1.Create an database engine (for example: mysql)
```go ```go
engine := xorm.Create("mysql://root:123@localhost/test") engine := xorm.Create("mysql://root:123@localhost/test")
``` ```
2. Define your struct 2.Define your struct
```go ```go
type User struct { type User struct {
@ -59,7 +59,8 @@ user := User{Id:1, Name:"xlw"}
rows, err := engine.Update(&user) rows, err := engine.Update(&user)
``` ```
3. Fetch a single object by user 3.Fetch a single object by user
```go ```go
var user = User{Id:27} var user = User{Id:27}
engine.Get(&user) engine.Get(&user)
@ -78,7 +79,8 @@ if err != nil {
} }
``` ```
1. Fetch a single object by where 1.Fetch a single object by where
```go ```go
var user Userinfo var user Userinfo
session.Where("id=?", 27).Get(&user) session.Where("id=?", 27).Get(&user)
@ -93,7 +95,7 @@ var user4 Userinfo
session.Where("name = ? and age < ?", "john", 88).Get(&user4) // even more complex session.Where("name = ? and age < ?", "john", 88).Get(&user4) // even more complex
``` ```
2. Fetch multiple objects 2.Fetch multiple objects
```go ```go
var allusers []Userinfo var allusers []Userinfo
@ -107,12 +109,12 @@ err := session.Find(&everyone)
``` ```
###***About Map Rules*** ###***About Map Rules***
1. Struct and struct's fields name should be Pascal style, and the table and column's name default is us 1.Struct and struct's fields name should be Pascal style, and the table and column's name default is us
for example: for example:
The structs Name 'UserInfo' will turn into the table name 'user_info', the same as the keyname. The structs Name 'UserInfo' will turn into the table name 'user_info', the same as the keyname.
If the keyname is 'UserName' will turn into the select colum 'user_name' If the keyname is 'UserName' will turn into the select colum 'user_name'
2. You have two method to change the rule. One is implement your own Map interface according IMapper, you can find the interface in mapper.go and set it to engine.Mapper 2.You have two method to change the rule. One is implement your own Map interface according IMapper, you can find the interface in mapper.go and set it to engine.Mapper
another is use field tag, field tag support the below keywords: another is use field tag, field tag support the below keywords:
[name] column name [name] column name