Merge branch 'dev' of github.com:go-xorm/xorm into dev
This commit is contained in:
commit
e7277992ad
|
@ -1,2 +1,2 @@
|
|||
[target]
|
||||
path = github.com/lunny/xorm
|
||||
path = github.com/go-xorm/xorm
|
|
@ -21,11 +21,11 @@ We appreciate any bug reports, but especially ones with self-contained
|
|||
further) test cases. It's especially helpful if you can submit a pull
|
||||
request with just the failing test case (you'll probably want to
|
||||
pattern it after the tests in
|
||||
[base_test.go](https://github.com/lunny/xorm/blob/master/base_test.go) AND
|
||||
[benchmark_base_test.go](https://github.com/lunny/xorm/blob/master/benchmark_base_test.go).
|
||||
[base_test.go](https://github.com/go-xorm/xorm/blob/master/base_test.go) AND
|
||||
[benchmark_base_test.go](https://github.com/go-xorm/xorm/blob/master/benchmark_base_test.go).
|
||||
|
||||
If you implements a new database interface, you maybe need to add a <databasename>_test.go file.
|
||||
For example, [mysql_test.go](https://github.com/lunny/xorm/blob/master/mysql_test.go)
|
||||
For example, [mysql_test.go](https://github.com/go-xorm/xorm/blob/master/mysql_test.go)
|
||||
|
||||
### New functionality
|
||||
|
||||
|
|
20
README.md
20
README.md
|
@ -1,8 +1,8 @@
|
|||
[中文](https://github.com/lunny/xorm/blob/master/README_CN.md)
|
||||
[中文](https://github.com/go-xorm/xorm/blob/master/README_CN.md)
|
||||
|
||||
Xorm is a simple and powerful ORM for Go.
|
||||
|
||||
[](https://drone.io/github.com/lunny/xorm/latest) [](http://gowalker.org/github.com/lunny/xorm) [](https://bitdeli.com/free "Bitdeli Badge")
|
||||
[](https://drone.io/github.com/go-xorm/xorm/latest) [](http://gowalker.org/github.com/go-xorm/xorm) [](https://bitdeli.com/free "Bitdeli Badge")
|
||||
|
||||
# Features
|
||||
|
||||
|
@ -18,7 +18,7 @@ Xorm is a simple and powerful ORM for Go.
|
|||
|
||||
* Query Cache speed up
|
||||
|
||||
* Database Reverse support, See [Xorm Tool README](https://github.com/lunny/xorm/blob/master/xorm/README.md)
|
||||
* Database Reverse support, See [Xorm Tool README](https://github.com/go-xorm/xorm/blob/master/xorm/README.md)
|
||||
|
||||
* Simple cascade loading support
|
||||
|
||||
|
@ -54,25 +54,25 @@ Drivers for Go's sql package which currently support database/sql includes:
|
|||
* Allowed int/int32/int64/uint/uint32/uint64/string as Primary Key type
|
||||
* Performance improvement for Get()/Find()/Iterate()
|
||||
|
||||
[More changelogs ...](https://github.com/lunny/xorm/blob/master/docs/Changelog.md)
|
||||
[More changelogs ...](https://github.com/go-xorm/xorm/blob/master/docs/Changelog.md)
|
||||
|
||||
# Installation
|
||||
|
||||
If you have [gopm](https://github.com/gpmgo/gopm) installed,
|
||||
|
||||
gopm get github.com/lunny/xorm
|
||||
gopm get github.com/go-xorm/xorm
|
||||
|
||||
Or
|
||||
|
||||
go get github.com/lunny/xorm
|
||||
go get github.com/go-xorm/xorm
|
||||
|
||||
# Documents
|
||||
|
||||
* [GoDoc](http://godoc.org/github.com/lunny/xorm)
|
||||
* [GoDoc](http://godoc.org/github.com/go-xorm/xorm)
|
||||
|
||||
* [GoWalker](http://gowalker.org/github.com/lunny/xorm)
|
||||
* [GoWalker](http://gowalker.org/github.com/go-xorm/xorm)
|
||||
|
||||
* [Quick Start](https://github.com/lunny/xorm/blob/master/docs/QuickStartEn.md)
|
||||
* [Quick Start](https://github.com/go-xorm/xorm/blob/master/docs/QuickStartEn.md)
|
||||
|
||||
# Cases
|
||||
|
||||
|
@ -96,7 +96,7 @@ Please visit [Xorm on Google Groups](https://groups.google.com/forum/#!forum/xor
|
|||
|
||||
# Contributors
|
||||
|
||||
If you want to pull request, please see [CONTRIBUTING](https://github.com/lunny/xorm/blob/master/CONTRIBUTING.md)
|
||||
If you want to pull request, please see [CONTRIBUTING](https://github.com/go-xorm/xorm/blob/master/CONTRIBUTING.md)
|
||||
|
||||
* [Lunny](https://github.com/lunny)
|
||||
* [Nashtsai](https://github.com/nashtsai)
|
||||
|
|
18
README_CN.md
18
README_CN.md
|
@ -1,10 +1,10 @@
|
|||
# xorm
|
||||
|
||||
[English](https://github.com/lunny/xorm/blob/master/README.md)
|
||||
[English](https://github.com/go-xorm/xorm/blob/master/README.md)
|
||||
|
||||
xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作非常简便。
|
||||
|
||||
[](https://drone.io/github.com/lunny/xorm/latest) [](http://gowalker.org/github.com/lunny/xorm)
|
||||
[](https://drone.io/github.com/go-xorm/xorm/latest) [](http://gowalker.org/github.com/go-xorm/xorm)
|
||||
|
||||
## 特性
|
||||
|
||||
|
@ -56,25 +56,25 @@ xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作
|
|||
* 查询函数 Get()/Find()/Iterate() 在性能上的改进
|
||||
|
||||
|
||||
[更多更新日志...](https://github.com/lunny/xorm/blob/master/docs/ChangelogCN.md)
|
||||
[更多更新日志...](https://github.com/go-xorm/xorm/blob/master/docs/ChangelogCN.md)
|
||||
|
||||
## 安装
|
||||
|
||||
推荐使用 [gopm](https://github.com/gpmgo/gopm) 进行安装:
|
||||
|
||||
gopm get github.com/lunny/xorm
|
||||
gopm get github.com/go-xorm/xorm
|
||||
|
||||
或者您也可以使用go工具进行安装:
|
||||
|
||||
go get github.com/lunny/xorm
|
||||
go get github.com/go-xorm/xorm
|
||||
|
||||
## 文档
|
||||
|
||||
* [快速开始](https://github.com/lunny/xorm/blob/master/docs/QuickStart.md)
|
||||
* [快速开始](https://github.com/go-xorm/xorm/blob/master/docs/QuickStart.md)
|
||||
|
||||
* [GoWalker代码文档](http://gowalker.org/github.com/lunny/xorm)
|
||||
* [GoWalker代码文档](http://gowalker.org/github.com/go-xorm/xorm)
|
||||
|
||||
* [Godoc代码文档](http://godoc.org/github.com/lunny/xorm)
|
||||
* [Godoc代码文档](http://godoc.org/github.com/go-xorm/xorm)
|
||||
|
||||
|
||||
## 案例
|
||||
|
@ -99,7 +99,7 @@ xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作
|
|||
|
||||
# 贡献者
|
||||
|
||||
如果您也想为Xorm贡献您的力量,请查看 [CONTRIBUTING](https://github.com/lunny/xorm/blob/master/CONTRIBUTING.md)
|
||||
如果您也想为Xorm贡献您的力量,请查看 [CONTRIBUTING](https://github.com/go-xorm/xorm/blob/master/CONTRIBUTING.md)
|
||||
|
||||
* [Lunny](https://github.com/lunny)
|
||||
* [Nashtsai](https://github.com/nashtsai)
|
||||
|
|
4
doc.go
4
doc.go
|
@ -9,7 +9,7 @@ Installation
|
|||
|
||||
Make sure you have installed Go 1.1+ and then:
|
||||
|
||||
go get github.com/lunny/xorm
|
||||
go get github.com/go-xorm/xorm
|
||||
|
||||
Create Engine
|
||||
|
||||
|
@ -137,6 +137,6 @@ The above 7 methods could use with condition methods.
|
|||
engine.Join("LEFT", "userdetail", "user.id=userdetail.id").Find()
|
||||
//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
|
||||
More usage, please visit https://github.com/go-xorm/xorm/blob/master/docs/QuickStartEn.md
|
||||
*/
|
||||
package xorm
|
||||
|
|
|
@ -11,20 +11,20 @@
|
|||
|
||||
Improvements:
|
||||
* Allowed int/int32/int64/uint/uint32/uint64/string as Primary Key type
|
||||
* Performance improvement for Get()/Find()/Iterate()
|
||||
* Performance improvement for Get()/Find()/Iterate()
|
||||
|
||||
|
||||
* **v0.2.3** : Improved documents; Optimistic Locking support; Timestamp with time zone support; Mapper change to tableMapper and columnMapper & added PrefixMapper & SuffixMapper support custom table or column name's prefix and suffix;Insert now return affected, err instead of id, err; Added UseBool & Distinct;
|
||||
* **v0.2.2** : Postgres drivers now support lib/pq; Added method Iterate for record by record to handler;Added SetMaxConns(go1.2+) support; some bugs fixed.
|
||||
* **v0.2.1** : Added database reverse tool, now support generate go & c++ codes, see [Xorm Tool README](https://github.com/lunny/xorm/blob/master/xorm/README.md); some bug fixed.
|
||||
* **v0.2.0** : Added Cache supported, select is speeder up 3~5x; Added SameMapper for same name between struct and table; Added Sync method for auto added tables, columns, indexes;
|
||||
* **v0.1.9** : Added postgres and mymysql supported; Added ` and ? supported on Raw SQL even if postgres; Added Cols, StoreEngine, Charset function, Added many column data type supported, please see [Mapping Rules](#mapping).
|
||||
* **v0.1.8** : Added union index and union unique supported, please see [Mapping Rules](#mapping).
|
||||
* **v0.1.7** : Added IConnectPool interface and NoneConnectPool, SysConnectPool, SimpleConnectPool the three implements. You can choose one of them and the default is SysConnectPool. You can customrize your own connection pool. struct Engine added Close method, It should be invoked before system exit.
|
||||
* **v0.1.6** : Added conversion interface support; added struct derive support; added single mapping support
|
||||
* **v0.1.5** : Added multi threads support; added Sql() function for struct query; Get function changed return inteface; MakeSession and Create are instead with NewSession and NewEngine.
|
||||
* **v0.1.4** : Added simple cascade load support; added more data type supports.
|
||||
* **v0.1.3** : Find function now supports both slice and map; Add Table function for multi tables and temperory tables support
|
||||
* **v0.1.2** : Insert function now supports both struct and slice pointer parameters, batch inserting and auto transaction
|
||||
* **v0.1.1** : Add Id, In functions and improved README
|
||||
* **v0.2.1** : Added database reverse tool, now support generate go & c++ codes, see [Xorm Tool README](https://github.com/go-xorm/xorm/blob/master/xorm/README.md); some bug fixed.
|
||||
* **v0.2.0** : Added Cache supported, select is speeder up 3~5x; Added SameMapper for same name between struct and table; Added Sync method for auto added tables, columns, indexes;
|
||||
* **v0.1.9** : Added postgres and mymysql supported; Added ` and ? supported on Raw SQL even if postgres; Added Cols, StoreEngine, Charset function, Added many column data type supported, please see [Mapping Rules](#mapping).
|
||||
* **v0.1.8** : Added union index and union unique supported, please see [Mapping Rules](#mapping).
|
||||
* **v0.1.7** : Added IConnectPool interface and NoneConnectPool, SysConnectPool, SimpleConnectPool the three implements. You can choose one of them and the default is SysConnectPool. You can customrize your own connection pool. struct Engine added Close method, It should be invoked before system exit.
|
||||
* **v0.1.6** : Added conversion interface support; added struct derive support; added single mapping support
|
||||
* **v0.1.5** : Added multi threads support; added Sql() function for struct query; Get function changed return inteface; MakeSession and Create are instead with NewSession and NewEngine.
|
||||
* **v0.1.4** : Added simple cascade load support; added more data type supports.
|
||||
* **v0.1.3** : Find function now supports both slice and map; Add Table function for multi tables and temperory tables support
|
||||
* **v0.1.2** : Insert function now supports both struct and slice pointer parameters, batch inserting and auto transaction
|
||||
* **v0.1.1** : Add Id, In functions and improved README
|
||||
* **v0.1.0** : Inital release.
|
|
@ -15,10 +15,10 @@
|
|||
|
||||
* **v0.2.3** : 改善了文档;提供了乐观锁支持;添加了带时区时间字段支持;Mapper现在分成表名Mapper和字段名Mapper,同时实现了表或字段的自定义前缀后缀;Insert方法的返回值含义从id, err更改为 affected, err,请大家注意;添加了UseBool 和 Distinct函数。
|
||||
* **v0.2.2** : Postgres驱动新增了对lib/pq的支持;新增了逐条遍历方法Iterate;新增了SetMaxConns(go1.2+)支持,修复了bug若干;
|
||||
* **v0.2.1** : 新增数据库反转工具,当前支持go和c++代码的生成,详见 [Xorm Tool README](https://github.com/lunny/xorm/blob/master/xorm/README.md); 修复了一些bug.
|
||||
* **v0.2.0** : 新增 [缓存](https://github.com/lunny/xorm/blob/master/docs/QuickStart.md#120)支持,查询速度提升3-5倍; 新增数据库表和Struct同名的映射方式; 新增Sync同步表结构;
|
||||
* **v0.1.9** : 新增 postgres 和 mymysql 驱动支持; 在Postgres中支持原始SQL语句中使用 ` 和 ? 符号; 新增Cols, StoreEngine, Charset 函数;SQL语句打印支持io.Writer接口,默认打印到控制台;新增更多的字段类型支持,详见 [映射规则](https://github.com/lunny/xorm/blob/master/docs/QuickStart.md#21);删除废弃的MakeSession和Create函数。
|
||||
* **v0.1.8** : 新增联合index,联合unique支持,请查看 [映射规则](https://github.com/lunny/xorm/blob/master/docs/QuickStart.md#21)。
|
||||
* **v0.2.1** : 新增数据库反转工具,当前支持go和c++代码的生成,详见 [Xorm Tool README](https://github.com/go-xorm/xorm/blob/master/xorm/README.md); 修复了一些bug.
|
||||
* **v0.2.0** : 新增 [缓存](https://github.com/go-xorm/xorm/blob/master/docs/QuickStart.md#120)支持,查询速度提升3-5倍; 新增数据库表和Struct同名的映射方式; 新增Sync同步表结构;
|
||||
* **v0.1.9** : 新增 postgres 和 mymysql 驱动支持; 在Postgres中支持原始SQL语句中使用 ` 和 ? 符号; 新增Cols, StoreEngine, Charset 函数;SQL语句打印支持io.Writer接口,默认打印到控制台;新增更多的字段类型支持,详见 [映射规则](https://github.com/go-xorm/xorm/blob/master/docs/QuickStart.md#21);删除废弃的MakeSession和Create函数。
|
||||
* **v0.1.8** : 新增联合index,联合unique支持,请查看 [映射规则](https://github.com/go-xorm/xorm/blob/master/docs/QuickStart.md#21)。
|
||||
* **v0.1.7** : 新增IConnectPool接口以及NoneConnectPool, SysConnectPool, SimpleConnectPool三种实现,可以选择不使用连接池,使用系统连接池和使用自带连接池三种实现,默认为SysConnectPool,即系统自带的连接池。同时支持自定义连接池。Engine新增Close方法,在系统退出时应调用此方法。
|
||||
* **v0.1.6** : 新增Conversion,支持自定义类型到数据库类型的转换;新增查询结构体自动检测匿名成员支持;新增单向映射支持;
|
||||
* **v0.1.5** : 新增对多线程的支持;新增Sql()函数;支持任意sql语句的struct查询;Get函数返回值变动;MakeSession和Create函数被NewSession和NewEngine函数替代;
|
||||
|
|
|
@ -45,7 +45,7 @@ xorm 快速入门
|
|||
```Go
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
engine, err := xorm.NewEngine("mysql", "root:123@/test?charset=utf8")
|
||||
defer engine.Close()
|
||||
|
@ -56,7 +56,7 @@ or
|
|||
```Go
|
||||
import (
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
engine, err = xorm.NewEngine("sqlite3", "./test.db")
|
||||
defer engine.Close()
|
||||
|
@ -125,9 +125,9 @@ engine.SetMapper(SameMapper{})
|
|||
同时需要注意的是:
|
||||
|
||||
<<<<<<< HEAD
|
||||
* 如果你使用了别的命名规则映射方案,也可以自己实现一个IMapper。
|
||||
* 如果你使用了别的命名规则映射方案,也可以自己实现一个IMapper。
|
||||
* 表名称和字段名称的映射规则默认是相同的,当然也可以设置为不同,如:
|
||||
|
||||
|
||||
=======
|
||||
* 如果你使用了别的命名规则映射方案,也可以自己实现一个IMapper。
|
||||
* 表名称和字段名称的映射规则默认是相同的,当然也可以设置为不同,如:
|
||||
|
@ -169,7 +169,7 @@ type User struct {
|
|||
}
|
||||
```
|
||||
|
||||
对于不同的数据库系统,数据类型其实是有些差异的。因此xorm中对数据类型有自己的定义,基本的原则是尽量兼容各种数据库的字段类型,具体的字段对应关系可以查看[字段类型对应表](https://github.com/lunny/xorm/blob/master/docs/COLUMNTYPE.md)。对于使用者,一般只要使用自己熟悉的数据库字段定义即可。
|
||||
对于不同的数据库系统,数据类型其实是有些差异的。因此xorm中对数据类型有自己的定义,基本的原则是尽量兼容各种数据库的字段类型,具体的字段对应关系可以查看[字段类型对应表](https://github.com/go-xorm/xorm/blob/master/docs/COLUMNTYPE.md)。对于使用者,一般只要使用自己熟悉的数据库字段定义即可。
|
||||
|
||||
具体的映射规则如下,另Tag中的关键字均不区分大小写,字段名区分大小写:
|
||||
|
||||
|
@ -181,7 +181,7 @@ type User struct {
|
|||
<td>pk</td><td>是否是Primary Key,如果在一个struct中有多个字段都使用了此标记,则这多个字段构成了复合主键,单主键当前支持int32,int,int64,uint32,uint,uint64,string这7种Go的数据类型,复合主键支持这7种Go的数据类型的组合。</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>当前支持30多种字段类型,详情参见 [字段类型](https://github.com/lunny/xorm/blob/master/docs/COLUMNTYPE.md)</td><td>字段类型</td>
|
||||
<td>当前支持30多种字段类型,详情参见 [字段类型](https://github.com/go-xorm/xorm/blob/master/docs/COLUMNTYPE.md)</td><td>字段类型</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>autoincr</td><td>是否是自增</td>
|
||||
|
@ -227,7 +227,7 @@ type User struct {
|
|||
|
||||
- 2.string类型默认映射为varchar(255),如果需要不同的定义,可以在tag中自定义
|
||||
|
||||
- 3.支持`type MyString string`等自定义的field,支持Slice, Map等field成员,这些成员默认存储为Text类型,并且默认将使用Json格式来序列化和反序列化。也支持数据库字段类型为Blob类型,如果是Blob类型,则先使用Json格式序列化再转成[]byte格式。当然[]byte或者[]uint8默认为Blob类型并且都以二进制方式存储。具体参见 [go类型<->数据库类型对应表](https://github.com/lunny/xorm/blob/master/docs/AutoMap.md)
|
||||
- 3.支持`type MyString string`等自定义的field,支持Slice, Map等field成员,这些成员默认存储为Text类型,并且默认将使用Json格式来序列化和反序列化。也支持数据库字段类型为Blob类型,如果是Blob类型,则先使用Json格式序列化再转成[]byte格式。当然[]byte或者[]uint8默认为Blob类型并且都以二进制方式存储。具体参见 [go类型<->数据库类型对应表](https://github.com/go-xorm/xorm/blob/master/docs/AutoMap.md)
|
||||
|
||||
- 4.实现了Conversion接口的类型或者结构体,将根据接口的转换方式在类型和数据库记录之间进行相互转换。
|
||||
```Go
|
||||
|
@ -242,7 +242,7 @@ type Conversion interface {
|
|||
|
||||
如果不使用tag来定义field对应的数据库字段类型,那么系统会自动给出一个默认的字段类型,对应表如下:
|
||||
|
||||
[go类型<->数据库类型对应表](https://github.com/lunny/xorm/blob/master/docs/AutoMap.md)
|
||||
[go类型<->数据库类型对应表](https://github.com/go-xorm/xorm/blob/master/docs/AutoMap.md)
|
||||
|
||||
<a name="30" id="30"></a>
|
||||
## 3.表结构操作
|
||||
|
@ -755,7 +755,7 @@ engine.ClearCache(new(User))
|
|||
|
||||
缓存的实现原理如下图所示:
|
||||
|
||||

|
||||

|
||||
|
||||
<a name="125" id="125"></a>
|
||||
## 12.事件
|
||||
|
@ -788,12 +788,12 @@ xorm支持两种方式的事件,一种是在Struct中的特定方法来作为
|
|||
xorm工具提供了xorm命令,能够帮助做很多事情。
|
||||
|
||||
### 13.1.反转命令
|
||||
参见 [xorm工具](https://github.com/lunny/xorm/tree/master/xorm)
|
||||
参见 [xorm工具](https://github.com/go-xorm/xorm/tree/master/xorm)
|
||||
|
||||
<a name="140" id="140"></a>
|
||||
## 14.Examples
|
||||
|
||||
请访问[https://github.com/lunny/xorm/tree/master/examples](https://github.com/lunny/xorm/tree/master/examples)
|
||||
请访问[https://github.com/go-xorm/xorm/tree/master/examples](https://github.com/go-xorm/xorm/tree/master/examples)
|
||||
|
||||
<a name="150" id="150"></a>
|
||||
## 15.案例
|
||||
|
|
|
@ -41,8 +41,8 @@ When using xorm, you can create multiple orm engines, an engine means a databse.
|
|||
```Go
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
)
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
engine, err := xorm.NewEngine("mysql", "root:123@/test?charset=utf8")
|
||||
defer engine.Close()
|
||||
```
|
||||
|
@ -52,18 +52,18 @@ or
|
|||
```Go
|
||||
import (
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
engine, err = xorm.NewEngine("sqlite3", "./test.db")
|
||||
defer engine.Close()
|
||||
defer engine.Close()
|
||||
```
|
||||
|
||||
Generally, you can only create one engine. Engine supports run on go rutines.
|
||||
|
||||
xorm supports four drivers now:
|
||||
|
||||
* Mysql: [github.com/Go-SQL-Driver/MySQL](https://github.com/Go-SQL-Driver/MySQL)
|
||||
|
||||
* Mysql: [github.com/Go-SQL-Driver/MySQL](https://github.com/Go-SQL-Driver/MySQL)
|
||||
|
||||
* MyMysql: [github.com/ziutek/mymysql/godrv](https://github.com/ziutek/mymysql/godrv)
|
||||
|
||||
* SQLite: [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3)
|
||||
|
@ -95,7 +95,7 @@ engine.Logger = f
|
|||
3.Engine support connection pool. The default pool is database/sql's and also you can use custom pool. Xorm provides two connection pool `xorm.NonConnectionPool` & `xorm.SimpleConnectPool`. If you want to use yourself pool, you can use `engine.SetPool` to set it.
|
||||
|
||||
* Use `engine.SetIdleConns()` to set idle connections.
|
||||
* Use `engine.SetMaxConns()` to set Max connections. This methods support only Go 1.2+.
|
||||
* Use `engine.SetMaxConns()` to set Max connections. This methods support only Go 1.2+.
|
||||
|
||||
<a name="20" id="20"></a>
|
||||
## 2.Define struct
|
||||
|
@ -150,7 +150,7 @@ type User struct {
|
|||
}
|
||||
```
|
||||
|
||||
对于不同的数据库系统,数据类型其实是有些差异的。因此xorm中对数据类型有自己的定义,基本的原则是尽量兼容各种数据库的字段类型,具体的字段对应关系可以查看[字段类型对应表](https://github.com/lunny/xorm/blob/master/docs/COLUMNTYPE.md)。
|
||||
对于不同的数据库系统,数据类型其实是有些差异的。因此xorm中对数据类型有自己的定义,基本的原则是尽量兼容各种数据库的字段类型,具体的字段对应关系可以查看[字段类型对应表](https://github.com/go-xorm/xorm/blob/master/docs/COLUMNTYPE.md)。
|
||||
|
||||
具体的映射规则如下,另Tag中的关键字均不区分大小写,字段名区分大小写:
|
||||
|
||||
|
@ -162,7 +162,7 @@ type User struct {
|
|||
<td>pk</td><td>是否是Primary Key,当前仅支持int64类型</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>当前支持30多种字段类型,详情参见 [字段类型](https://github.com/lunny/xorm/blob/master/docs/COLUMNTYPE.md)</td><td>字段类型</td>
|
||||
<td>当前支持30多种字段类型,详情参见 [字段类型](https://github.com/go-xorm/xorm/blob/master/docs/COLUMNTYPE.md)</td><td>字段类型</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>autoincr</td><td>是否是自增</td>
|
||||
|
@ -216,7 +216,7 @@ type Conversion interface {
|
|||
FromDB([]byte) error
|
||||
ToDB() ([]byte, error)
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
<a name="30" id="30"></a>
|
||||
## 3.表结构操作
|
||||
|
@ -264,7 +264,7 @@ xorm支持获取表结构信息,通过调用`engine.DBMetas()`可以获取到
|
|||
调用方法如下:
|
||||
```Go
|
||||
err := engine.Sync(new(User))
|
||||
```
|
||||
```
|
||||
|
||||
<a name="50" id="50"></a>
|
||||
## 4.插入数据
|
||||
|
@ -425,59 +425,59 @@ Having的参数字符串
|
|||
当从一个struct来生成查询条件或更新字段时,xorm会判断struct的field是否为0,"",nil,如果为以上则不当做查询条件或者更新内容。因为bool类型只有true和false两种值,因此默认所有bool类型不会作为查询条件或者更新字段。如果可以使用此方法,如果默认不传参数,则所有的bool字段都将会被使用,如果参数不为空,则参数中指定的为字段名,则这些字段对应的bool值将被使用。
|
||||
|
||||
* Cascade(bool)
|
||||
是否自动关联查询field中的数据,如果struct的field也是一个struct并且映射为某个Id,则可以在查询时自动调用Get方法查询出对应的数据。
|
||||
是否自动关联查询field中的数据,如果struct的field也是一个struct并且映射为某个Id,则可以在查询时自动调用Get方法查询出对应的数据。
|
||||
|
||||
<a name="50" id="50"></a>
|
||||
### 5.3.Get one record
|
||||
Fetch a single object by user
|
||||
|
||||
```Go
|
||||
var user = User{Id:27}
|
||||
has, err := engine.Get(&user)
|
||||
// or has, err := engine.Id(27).Get(&user)
|
||||
|
||||
var user = User{Name:"xlw"}
|
||||
has, err := engine.Get(&user)
|
||||
```
|
||||
### 5.3.Get one record
|
||||
Fetch a single object by user
|
||||
|
||||
```Go
|
||||
var user = User{Id:27}
|
||||
has, err := engine.Get(&user)
|
||||
// or has, err := engine.Id(27).Get(&user)
|
||||
|
||||
var user = User{Name:"xlw"}
|
||||
has, err := engine.Get(&user)
|
||||
```
|
||||
|
||||
<a name="60" id="60"></a>
|
||||
### 5.4.Find
|
||||
Fetch multipe objects into a slice or a map, use Find:
|
||||
|
||||
```Go
|
||||
var everyone []Userinfo
|
||||
err := engine.Find(&everyone)
|
||||
|
||||
users := make(map[int64]Userinfo)
|
||||
err := engine.Find(&users)
|
||||
```
|
||||
|
||||
* also you can use Where, Limit
|
||||
|
||||
```Go
|
||||
var allusers []Userinfo
|
||||
err := engine.Where("id > ?", "3").Limit(10,20).Find(&allusers) //Get id>3 limit 10 offset 20
|
||||
```
|
||||
|
||||
* or you can use a struct query
|
||||
|
||||
```Go
|
||||
var tenusers []Userinfo
|
||||
err := engine.Limit(10).Find(&tenusers, &Userinfo{Name:"xlw"}) //Get All Name="xlw" limit 10 offset 0
|
||||
```
|
||||
|
||||
* or In function
|
||||
|
||||
```Go
|
||||
var tenusers []Userinfo
|
||||
err := engine.In("id", 1, 3, 5).Find(&tenusers) //Get All id in (1, 3, 5)
|
||||
```
|
||||
|
||||
* The default will query all columns of a table. Use Cols function if you want to select some columns
|
||||
|
||||
```Go
|
||||
var tenusers []Userinfo
|
||||
err := engine.Cols("id", "name").Find(&tenusers) //Find only id and name
|
||||
### 5.4.Find
|
||||
Fetch multipe objects into a slice or a map, use Find:
|
||||
|
||||
```Go
|
||||
var everyone []Userinfo
|
||||
err := engine.Find(&everyone)
|
||||
|
||||
users := make(map[int64]Userinfo)
|
||||
err := engine.Find(&users)
|
||||
```
|
||||
|
||||
* also you can use Where, Limit
|
||||
|
||||
```Go
|
||||
var allusers []Userinfo
|
||||
err := engine.Where("id > ?", "3").Limit(10,20).Find(&allusers) //Get id>3 limit 10 offset 20
|
||||
```
|
||||
|
||||
* or you can use a struct query
|
||||
|
||||
```Go
|
||||
var tenusers []Userinfo
|
||||
err := engine.Limit(10).Find(&tenusers, &Userinfo{Name:"xlw"}) //Get All Name="xlw" limit 10 offset 0
|
||||
```
|
||||
|
||||
* or In function
|
||||
|
||||
```Go
|
||||
var tenusers []Userinfo
|
||||
err := engine.In("id", 1, 3, 5).Find(&tenusers) //Get All id in (1, 3, 5)
|
||||
```
|
||||
|
||||
* The default will query all columns of a table. Use Cols function if you want to select some columns
|
||||
|
||||
```Go
|
||||
var tenusers []Userinfo
|
||||
err := engine.Cols("id", "name").Find(&tenusers) //Find only id and name
|
||||
```
|
||||
|
||||
<a name="70" id="70"></a>
|
||||
|
@ -542,44 +542,44 @@ engine.Id(1).Get(&user)
|
|||
engine.Id(1).Update(&user)
|
||||
// UPDATE user SET ..., version = version + 1 WHERE id = ? AND version = ?
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="80" id="80"></a>
|
||||
## 7.Delete one or more records
|
||||
Delete one or more records
|
||||
## 7.Delete one or more records
|
||||
Delete one or more records
|
||||
|
||||
* delete by id
|
||||
|
||||
```Go
|
||||
err := engine.Id(1).Delete(&User{})
|
||||
|
||||
```Go
|
||||
err := engine.Id(1).Delete(&User{})
|
||||
```
|
||||
|
||||
|
||||
* delete by other conditions
|
||||
|
||||
```Go
|
||||
err := engine.Delete(&User{Name:"xlw"})
|
||||
```
|
||||
```
|
||||
|
||||
<a name="90" id="90"></a>
|
||||
## 8.Execute SQL query
|
||||
|
||||
Of course, SQL execution is also provided.
|
||||
|
||||
If select then use Query
|
||||
|
||||
```Go
|
||||
sql := "select * from userinfo"
|
||||
results, err := engine.Query(sql)
|
||||
```
|
||||
<a name="90" id="90"></a>
|
||||
## 8.Execute SQL query
|
||||
|
||||
<a name="100" id="100"></a>
|
||||
## 9.Execute SQL command
|
||||
If insert, update or delete then use Exec
|
||||
|
||||
```Go
|
||||
sql = "update userinfo set username=? where id=?"
|
||||
res, err := engine.Exec(sql, "xiaolun", 1)
|
||||
```
|
||||
Of course, SQL execution is also provided.
|
||||
|
||||
If select then use Query
|
||||
|
||||
```Go
|
||||
sql := "select * from userinfo"
|
||||
results, err := engine.Query(sql)
|
||||
```
|
||||
|
||||
<a name="100" id="100"></a>
|
||||
## 9.Execute SQL command
|
||||
If insert, update or delete then use Exec
|
||||
|
||||
```Go
|
||||
sql = "update userinfo set username=? where id=?"
|
||||
res, err := engine.Exec(sql, "xiaolun", 1)
|
||||
```
|
||||
|
||||
<a name="110" id="110"></a>
|
||||
## 10.Transaction
|
||||
|
@ -613,8 +613,8 @@ if err != nil {
|
|||
err = session.Commit()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
```
|
||||
}
|
||||
```
|
||||
|
||||
<a name="120" id="120"></a>
|
||||
## 11.缓存
|
||||
|
@ -654,19 +654,19 @@ engine.ClearCache(new(User))
|
|||
|
||||
Cache implement theory below:
|
||||
|
||||

|
||||

|
||||
|
||||
<a name="130" id="130"></a>
|
||||
## 12.xorm tool
|
||||
xorm工具提供了xorm命令,能够帮助做很多事情。
|
||||
|
||||
### 12.1.Reverse command
|
||||
Please visit [xorm tool](https://github.com/lunny/xorm/tree/master/xorm)
|
||||
Please visit [xorm tool](https://github.com/go-xorm/xorm/tree/master/xorm)
|
||||
|
||||
<a name="140" id="140"></a>
|
||||
## 13.Examples
|
||||
|
||||
请访问[https://github.com/lunny/xorm/tree/master/examples](https://github.com/lunny/xorm/tree/master/examples)
|
||||
请访问[https://github.com/go-xorm/xorm/tree/master/examples](https://github.com/go-xorm/xorm/tree/master/examples)
|
||||
|
||||
<a name="150" id="150"></a>
|
||||
## 14.Cases
|
||||
|
@ -680,14 +680,14 @@ Please visit [xorm tool](https://github.com/lunny/xorm/tree/master/xorm)
|
|||
* [VeryHour](http://veryhour.com)
|
||||
|
||||
<a name="160"></a>
|
||||
## 15.FAQ
|
||||
|
||||
1.How the xorm tag use both with json?
|
||||
|
||||
Use space.
|
||||
|
||||
```Go
|
||||
type User struct {
|
||||
Name string `json:"name" xorm:"name"`
|
||||
}
|
||||
## 15.FAQ
|
||||
|
||||
1.How the xorm tag use both with json?
|
||||
|
||||
Use space.
|
||||
|
||||
```Go
|
||||
type User struct {
|
||||
Name string `json:"name" xorm:"name"`
|
||||
}
|
||||
```
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/lunny/xorm/caches"
|
||||
"github.com/go-xorm/xorm"
|
||||
"github.com/go-xorm/xorm/caches"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
)
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"runtime"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"runtime"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
_ "github.com/bylevel/pq"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
[deps]
|
||||
github.com/lunny/xorm=../
|
||||
github.com/go-xorm/xorm=../
|
|
@ -5,11 +5,11 @@ xorm tools is a set of tools for database operation.
|
|||
|
||||
## Install
|
||||
|
||||
`go get github.com/lunny/xorm/xorm`
|
||||
`go get github.com/go-xorm/xorm/xorm`
|
||||
|
||||
and you should install the depends below:
|
||||
|
||||
* github.com/lunny/xorm
|
||||
* github.com/go-xorm/xorm
|
||||
|
||||
* Mysql: [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/lunny/xorm/core"
|
||||
"github.com/go-xorm/core"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/lunny/xorm/core"
|
||||
"github.com/go-xorm/core"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/go-xorm/core"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"text/template"
|
||||
"github.com/lunny/xorm/core"
|
||||
)
|
||||
|
||||
type LangTmpl struct {
|
||||
|
|
|
@ -14,8 +14,8 @@ import (
|
|||
_ "github.com/bylevel/pq"
|
||||
"github.com/dvirsky/go-pylog/logging"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/lunny/xorm/core"
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/go-xorm/xorm"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
_ "github.com/ziutek/mymysql/godrv"
|
||||
|
|
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/go-xorm/xorm"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue