improved docs
This commit is contained in:
parent
76ab72dc3a
commit
c9192441c8
12
doc.go
12
doc.go
|
@ -5,9 +5,10 @@
|
||||||
/*
|
/*
|
||||||
Package xorm is a simple and powerful ORM for Go.
|
Package xorm is a simple and powerful ORM for Go.
|
||||||
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
|
|
||||||
|
Make sure you have installed Go 1.1+ and then:
|
||||||
|
|
||||||
go get github.com/lunny/xorm
|
go get github.com/lunny/xorm
|
||||||
|
|
||||||
Create Engine
|
Create Engine
|
||||||
|
@ -20,7 +21,7 @@ Method NewEngine's parameters is the same as sql.Open. It depends
|
||||||
drivers' implementation.
|
drivers' implementation.
|
||||||
Generally, one engine is enough. You can set it as package variable.
|
Generally, one engine is enough. You can set it as package variable.
|
||||||
|
|
||||||
Usage
|
Raw Methods
|
||||||
|
|
||||||
Xorm also support raw sql execution:
|
Xorm also support raw sql execution:
|
||||||
|
|
||||||
|
@ -32,6 +33,8 @@ Xorm also support raw sql execution:
|
||||||
|
|
||||||
affected, err := engine.Exec("update user set .... where ...")
|
affected, err := engine.Exec("update user set .... where ...")
|
||||||
|
|
||||||
|
ORM Methods
|
||||||
|
|
||||||
There are 7 major ORM methods and many helpful methods to use to operate database.
|
There are 7 major ORM methods and many helpful methods to use to operate database.
|
||||||
|
|
||||||
1. Insert one or multipe records to database
|
1. Insert one or multipe records to database
|
||||||
|
@ -77,7 +80,7 @@ There are 7 major ORM methods and many helpful methods to use to operate databas
|
||||||
counts, err := engine.Count(&user)
|
counts, err := engine.Count(&user)
|
||||||
// SELECT count(*) AS total FROM user
|
// SELECT count(*) AS total FROM user
|
||||||
|
|
||||||
Condition
|
Conditions
|
||||||
|
|
||||||
The above 7 methods could use with condition methods.
|
The above 7 methods could use with condition methods.
|
||||||
|
|
||||||
|
@ -85,6 +88,8 @@ The above 7 methods could use with condition methods.
|
||||||
|
|
||||||
engine.Id(1).Get(&user)
|
engine.Id(1).Get(&user)
|
||||||
// SELECT * FROM user WHERE id = 1
|
// SELECT * FROM user WHERE id = 1
|
||||||
|
engine.In("id", 1, 2, 3).Find(&users)
|
||||||
|
// SELECT * FROM user WHERE id IN (1, 2, 3)
|
||||||
|
|
||||||
2. Where, And, Or
|
2. Where, And, Or
|
||||||
|
|
||||||
|
@ -125,5 +130,6 @@ The above 7 methods could use with condition methods.
|
||||||
engine.Join("LEFT", "userdetail", "user.id=userdetail.id").Find()
|
engine.Join("LEFT", "userdetail", "user.id=userdetail.id").Find()
|
||||||
//SELECT * FROM user LEFT JOIN userdetail ON user.id=userdetail.id
|
//SELECT * FROM user LEFT JOIN userdetail ON user.id=userdetail.id
|
||||||
|
|
||||||
|
More usage, please visit https://github.com/lunny/xorm/blob/master/docs/QuickStartEn.md
|
||||||
*/
|
*/
|
||||||
package xorm
|
package xorm
|
||||||
|
|
|
@ -6,6 +6,7 @@ xorm 快速入门
|
||||||
* [2.1.名称映射规则](#21)
|
* [2.1.名称映射规则](#21)
|
||||||
* [2.2.使用Table和Tag改变名称映射](#22)
|
* [2.2.使用Table和Tag改变名称映射](#22)
|
||||||
* [2.3.Column属性定义](#23)
|
* [2.3.Column属性定义](#23)
|
||||||
|
* [2.4.默认字段类型](#24)
|
||||||
* [3.表结构操作](#30)
|
* [3.表结构操作](#30)
|
||||||
* [3.1 获取数据库信息](#31)
|
* [3.1 获取数据库信息](#31)
|
||||||
* [3.2 表操作](#32)
|
* [3.2 表操作](#32)
|
||||||
|
@ -70,8 +71,6 @@ xorm当前支持四种驱动如下:
|
||||||
|
|
||||||
* Postgres: [github.com/lib/pq](https://github.com/lib/pq)
|
* Postgres: [github.com/lib/pq](https://github.com/lib/pq)
|
||||||
|
|
||||||
* Postgres: [github.com/bylevel/pq](https://github.com/bylevel/pq)
|
|
||||||
|
|
||||||
NewEngine传入的参数和`sql.Open`传入的参数完全相同,因此,使用哪个驱动前,请查看此驱动中关于传入参数的说明文档。
|
NewEngine传入的参数和`sql.Open`传入的参数完全相同,因此,使用哪个驱动前,请查看此驱动中关于传入参数的说明文档。
|
||||||
|
|
||||||
在engine创建完成后可以进行一些设置,如:
|
在engine创建完成后可以进行一些设置,如:
|
||||||
|
@ -99,7 +98,6 @@ engine.Logger = f
|
||||||
* 如果需要设置连接池的空闲数大小,可以使用`engine.SetIdleConns()`来实现。
|
* 如果需要设置连接池的空闲数大小,可以使用`engine.SetIdleConns()`来实现。
|
||||||
* 如果需要设置最大打开连接数,则可以使用`engine.SetMaxConns()`来实现。
|
* 如果需要设置最大打开连接数,则可以使用`engine.SetMaxConns()`来实现。
|
||||||
|
|
||||||
|
|
||||||
<a name="20" id="20"></a>
|
<a name="20" id="20"></a>
|
||||||
## 2.定义表结构体
|
## 2.定义表结构体
|
||||||
|
|
||||||
|
@ -201,6 +199,13 @@ type Conversion interface {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<a name="24" id="24"></a>
|
||||||
|
### 2.4.默认字段类型
|
||||||
|
|
||||||
|
如果不使用tag来定义field对应的数据库字段类型,那么系统会自动给出一个默认的字段类型,对应表如下:
|
||||||
|
|
||||||
|
[go类型<->数据库类型对应表](https://github.com/lunny/xorm/blob/master/docs/AutoMap.md)
|
||||||
|
|
||||||
<a name="30" id="30"></a>
|
<a name="30" id="30"></a>
|
||||||
## 3.表结构操作
|
## 3.表结构操作
|
||||||
|
|
||||||
|
@ -682,6 +687,10 @@ money float64 `xorm:"Numeric"`
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* 为什么Update时Sqlite3返回的affected和其它数据库不一样?
|
||||||
|
|
||||||
|
答:Sqlite3默认Update时返回的是update的查询条件的记录数条数,不管记录是否真的有更新。而Mysql和Postgres默认情况下都是只返回记录中有字段改变的记录数。
|
||||||
|
|
||||||
<a name="170" id="170"></a>
|
<a name="170" id="170"></a>
|
||||||
## 16.讨论
|
## 16.讨论
|
||||||
请加入QQ群:280360085 进行讨论。
|
请加入QQ群:280360085 进行讨论。
|
||||||
|
|
Loading…
Reference in New Issue