docs added iterate
This commit is contained in:
parent
fc17734817
commit
c79a02eb7e
|
@ -14,8 +14,9 @@ xorm 快速入门
|
||||||
* [6.1.查询条件方法](#61)
|
* [6.1.查询条件方法](#61)
|
||||||
* [6.2.Get方法](#62)
|
* [6.2.Get方法](#62)
|
||||||
* [6.3.Find方法](#63)
|
* [6.3.Find方法](#63)
|
||||||
* [6.4.Count方法](#64)
|
* [6.4.Iterate方法](#64)
|
||||||
* [6.5.匿名结构体成员](#65)
|
* [6.5.Count方法](#65)
|
||||||
|
* [6.6.匿名结构体成员](#66)
|
||||||
* [7.更新数据](#70)
|
* [7.更新数据](#70)
|
||||||
* [8.删除数据](#80)
|
* [8.删除数据](#80)
|
||||||
* [9.执行SQL查询](#90)
|
* [9.执行SQL查询](#90)
|
||||||
|
@ -25,7 +26,7 @@ xorm 快速入门
|
||||||
* [13.Examples](#130)
|
* [13.Examples](#130)
|
||||||
* [14.案例](#140)
|
* [14.案例](#140)
|
||||||
* [15.FAQ](#150)
|
* [15.FAQ](#150)
|
||||||
* [15.讨论](#160)
|
* [16.讨论](#160)
|
||||||
|
|
||||||
<a name="10" id="10"></a>
|
<a name="10" id="10"></a>
|
||||||
## 1.创建Orm引擎
|
## 1.创建Orm引擎
|
||||||
|
@ -344,7 +345,18 @@ err := engine.Where("age > ? or name=?)", 30, "xlw").Limit(20, 10).Find(&users)
|
||||||
```
|
```
|
||||||
|
|
||||||
<a name="64" id="64"></a>
|
<a name="64" id="64"></a>
|
||||||
### 6.4.Count方法
|
### 6.4.Iterate方法
|
||||||
|
|
||||||
|
Iterate方法提供逐条执行查询到的记录的方法,他所能使用的条件和Find方法完全相同
|
||||||
|
```Go
|
||||||
|
err := engine.Where("age > ? or name=?)", 30, "xlw").Iterate(new(Userinfo), func(i int, bean interface{})error{
|
||||||
|
user := bean.(*Userinfo)
|
||||||
|
//do somthing use i and user
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
<a name="65" id="65"></a>
|
||||||
|
### 6.5.Count方法
|
||||||
|
|
||||||
统计数据使用`Count`方法,Count方法的参数为struct的指针并且成为查询条件。
|
统计数据使用`Count`方法,Count方法的参数为struct的指针并且成为查询条件。
|
||||||
```Go
|
```Go
|
||||||
|
@ -352,7 +364,7 @@ user := new(User)
|
||||||
total, err := engine.Where("id >?", 1).Count(user)
|
total, err := engine.Where("id >?", 1).Count(user)
|
||||||
```
|
```
|
||||||
|
|
||||||
<a name="65" id-"65"></a>
|
<a name="66" id="66"></a>
|
||||||
### 6.5.匿名结构体成员
|
### 6.5.匿名结构体成员
|
||||||
|
|
||||||
如果在struct中拥有一个struct,并且在Tag中标记为extends,那么该结构体的成员将作为本结构体的成员进行映射。
|
如果在struct中拥有一个struct,并且在Tag中标记为extends,那么该结构体的成员将作为本结构体的成员进行映射。
|
||||||
|
@ -472,17 +484,21 @@ engine.ClearCache(new(User))
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 12.Examples
|
<a name="130" id="130"></a>
|
||||||
|
## 13.Examples
|
||||||
|
|
||||||
请访问[https://github.com/lunny/xorm/tree/master/examples](https://github.com/lunny/xorm/tree/master/examples)
|
请访问[https://github.com/lunny/xorm/tree/master/examples](https://github.com/lunny/xorm/tree/master/examples)
|
||||||
|
|
||||||
<a name="130" id="130"></a>
|
<a name="140" id="140"></a>
|
||||||
## 13.案例
|
## 14.案例
|
||||||
|
|
||||||
* [GoDaily Go语言学习网站](http://godaily.org),源代码 [github.com/govc/godaily](http://github.com/govc/godaily)
|
* [GoDaily Go语言学习网站](http://godaily.org),源代码 [github.com/govc/godaily](http://github.com/govc/godaily)
|
||||||
|
|
||||||
* [godaily](http://godaily.org) 和对应的源代码[github.com/govc/godaily](http://github.com/govc/godaily)
|
* [Sudochina](http://sudochina.com) 和对应的源代码[github.com/insionng/toropress](http://github.com/insionng/toropress)
|
||||||
|
|
||||||
<a name="140" id="140"></a>
|
* [VeryHour](http://veryhour.org)
|
||||||
## 14.讨论
|
|
||||||
|
|
||||||
|
<a name="150" id="150"></a>
|
||||||
|
## 15.讨论
|
||||||
请加入QQ群:280360085 进行讨论。
|
请加入QQ群:280360085 进行讨论。
|
||||||
|
|
|
@ -129,27 +129,36 @@ var tenusers []Userinfo
|
||||||
err := engine.Cols("id", "name").Find(&tenusers) //Find only id and name
|
err := engine.Cols("id", "name").Find(&tenusers) //Find only id and name
|
||||||
```
|
```
|
||||||
|
|
||||||
7.Delete
|
7.Iterate, like find, but handle records one by one
|
||||||
|
|
||||||
7.1 deleted by id
|
```Go
|
||||||
|
err := engine.Where("age > ? or name=?)", 30, "xlw").Iterate(new(Userinfo), func(i int, bean interface{})error{
|
||||||
|
user := bean.(*Userinfo)
|
||||||
|
//do somthing use i and user
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
8.Delete one or more records
|
||||||
|
|
||||||
|
8.1 deleted by id
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
err := engine.Id(1).Delete(&User{})
|
err := engine.Id(1).Delete(&User{})
|
||||||
```
|
```
|
||||||
|
|
||||||
7.2 deleted by other conditions
|
8.2 deleted by other conditions
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
err := engine.Delete(&User{Name:"xlw"})
|
err := engine.Delete(&User{Name:"xlw"})
|
||||||
```
|
```
|
||||||
|
|
||||||
8.Count
|
9.Count
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
total, err := engine.Where("id > ?", 5).Count(&User{Name:"xlw"})
|
total, err := engine.Where("id > ?", 5).Count(&User{Name:"xlw"})
|
||||||
```
|
```
|
||||||
|
|
||||||
9.Cache
|
10.Cache
|
||||||
```Go
|
```Go
|
||||||
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
|
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
|
||||||
engine.SetDefaultCacher(cacher)
|
engine.SetDefaultCacher(cacher)
|
||||||
|
|
Loading…
Reference in New Issue