renamed import path

This commit is contained in:
Nash Tsai 2014-04-11 17:16:43 +08:00
parent 128db9c792
commit 1213bc14b5
25 changed files with 173 additions and 173 deletions

View File

@ -1,2 +1,2 @@
[target] [target]
path = github.com/lunny/xorm path = github.com/go-xorm/xorm

View File

@ -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 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 request with just the failing test case (you'll probably want to
pattern it after the tests in pattern it after the tests in
[base_test.go](https://github.com/lunny/xorm/blob/master/base_test.go) AND [base_test.go](https://github.com/go-xorm/xorm/blob/master/base_test.go) AND
[benchmark_base_test.go](https://github.com/lunny/xorm/blob/master/benchmark_base_test.go). [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. 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 ### New functionality

View File

@ -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. Xorm is a simple and powerful ORM for Go.
[![Build Status](https://drone.io/github.com/lunny/xorm/status.png)](https://drone.io/github.com/lunny/xorm/latest) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/lunny/xorm) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/lunny/xorm/trend.png)](https://bitdeli.com/free "Bitdeli Badge") [![Build Status](https://drone.io/github.com/go-xorm/xorm/status.png)](https://drone.io/github.com/go-xorm/xorm/latest) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/go-xorm/xorm) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/lunny/xorm/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
# Features # Features
@ -18,7 +18,7 @@ Xorm is a simple and powerful ORM for Go.
* Query Cache speed up * 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 * 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 * Allowed int/int32/int64/uint/uint32/uint64/string as Primary Key type
* Performance improvement for Get()/Find()/Iterate() * 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 # Installation
If you have [gopm](https://github.com/gpmgo/gopm) installed, If you have [gopm](https://github.com/gpmgo/gopm) installed,
gopm get github.com/lunny/xorm gopm get github.com/go-xorm/xorm
Or Or
go get github.com/lunny/xorm go get github.com/go-xorm/xorm
# Documents # 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 # Cases
@ -96,7 +96,7 @@ Please visit [Xorm on Google Groups](https://groups.google.com/forum/#!forum/xor
# Contributors # 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) * [Lunny](https://github.com/lunny)
* [Nashtsai](https://github.com/nashtsai) * [Nashtsai](https://github.com/nashtsai)

View File

@ -1,10 +1,10 @@
# xorm # 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库. 通过它可以使数据库操作非常简便。 xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作非常简便。
[![Build Status](https://drone.io/github.com/lunny/xorm/status.png)](https://drone.io/github.com/lunny/xorm/latest) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/lunny/xorm) [![Build Status](https://drone.io/github.com/go-xorm/xorm/status.png)](https://drone.io/github.com/go-xorm/xorm/latest) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/go-xorm/xorm)
## 特性 ## 特性
@ -56,25 +56,25 @@ xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作
* 查询函数 Get()/Find()/Iterate() 在性能上的改进 * 查询函数 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](https://github.com/gpmgo/gopm) 进行安装:
gopm get github.com/lunny/xorm gopm get github.com/go-xorm/xorm
或者您也可以使用go工具进行安装 或者您也可以使用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) * [Lunny](https://github.com/lunny)
* [Nashtsai](https://github.com/nashtsai) * [Nashtsai](https://github.com/nashtsai)

4
doc.go
View File

@ -9,7 +9,7 @@ Installation
Make sure you have installed Go 1.1+ and then: 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 Create Engine
@ -137,6 +137,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 More usage, please visit https://github.com/go-xorm/xorm/blob/master/docs/QuickStartEn.md
*/ */
package xorm package xorm

View File

@ -11,20 +11,20 @@
Improvements: Improvements:
* Allowed int/int32/int64/uint/uint32/uint64/string as Primary Key type * 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.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 handlerAdded SetMaxConns(go1.2+) support; some bugs fixed. * **v0.2.2** : Postgres drivers now support lib/pq; Added method Iterate for record by record to handlerAdded 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.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.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.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.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.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.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.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.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.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.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.1** : Add Id, In functions and improved README
* **v0.1.0** : Inital release. * **v0.1.0** : Inital release.

View File

@ -15,10 +15,10 @@
* **v0.2.3** : 改善了文档提供了乐观锁支持添加了带时区时间字段支持Mapper现在分成表名Mapper和字段名Mapper同时实现了表或字段的自定义前缀后缀Insert方法的返回值含义从id, err更改为 affected, err请大家注意添加了UseBool 和 Distinct函数。 * **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.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.1** : 新增数据库反转工具当前支持go和c++代码的生成,详见 [Xorm Tool README](https://github.com/go-xorm/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.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/lunny/xorm/blob/master/docs/QuickStart.md#21)删除废弃的MakeSession和Create函数。 * **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/lunny/xorm/blob/master/docs/QuickStart.md#21)。 * **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.7** : 新增IConnectPool接口以及NoneConnectPool, SysConnectPool, SimpleConnectPool三种实现可以选择不使用连接池使用系统连接池和使用自带连接池三种实现默认为SysConnectPool即系统自带的连接池。同时支持自定义连接池。Engine新增Close方法在系统退出时应调用此方法。
* **v0.1.6** : 新增Conversion支持自定义类型到数据库类型的转换新增查询结构体自动检测匿名成员支持新增单向映射支持 * **v0.1.6** : 新增Conversion支持自定义类型到数据库类型的转换新增查询结构体自动检测匿名成员支持新增单向映射支持
* **v0.1.5** : 新增对多线程的支持新增Sql()函数支持任意sql语句的struct查询Get函数返回值变动MakeSession和Create函数被NewSession和NewEngine函数替代 * **v0.1.5** : 新增对多线程的支持新增Sql()函数支持任意sql语句的struct查询Get函数返回值变动MakeSession和Create函数被NewSession和NewEngine函数替代

View File

@ -45,7 +45,7 @@ xorm 快速入门
```Go ```Go
import ( import (
_ "github.com/go-sql-driver/mysql" _ "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") engine, err := xorm.NewEngine("mysql", "root:123@/test?charset=utf8")
defer engine.Close() defer engine.Close()
@ -56,7 +56,7 @@ or
```Go ```Go
import ( import (
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
) )
engine, err = xorm.NewEngine("sqlite3", "./test.db") engine, err = xorm.NewEngine("sqlite3", "./test.db")
defer engine.Close() defer engine.Close()
@ -125,9 +125,9 @@ engine.SetMapper(SameMapper{})
同时需要注意的是: 同时需要注意的是:
<<<<<<< HEAD <<<<<<< HEAD
* 如果你使用了别的命名规则映射方案也可以自己实现一个IMapper。 * 如果你使用了别的命名规则映射方案也可以自己实现一个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中的关键字均不区分大小写字段名区分大小写 具体的映射规则如下另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> <td>pk</td><td>是否是Primary Key如果在一个struct中有多个字段都使用了此标记则这多个字段构成了复合主键单主键当前支持int32,int,int64,uint32,uint,uint64,string这7种Go的数据类型复合主键支持这7种Go的数据类型的组合。</td>
</tr> </tr>
<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>
<tr> <tr>
<td>autoincr</td><td>是否是自增</td> <td>autoincr</td><td>是否是自增</td>
@ -227,7 +227,7 @@ type User struct {
- 2.string类型默认映射为varchar(255)如果需要不同的定义可以在tag中自定义 - 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接口的类型或者结构体将根据接口的转换方式在类型和数据库记录之间进行相互转换。 - 4.实现了Conversion接口的类型或者结构体将根据接口的转换方式在类型和数据库记录之间进行相互转换。
```Go ```Go
@ -242,7 +242,7 @@ type Conversion interface {
如果不使用tag来定义field对应的数据库字段类型那么系统会自动给出一个默认的字段类型对应表如下 如果不使用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> <a name="30" id="30"></a>
## 3.表结构操作 ## 3.表结构操作
@ -755,7 +755,7 @@ engine.ClearCache(new(User))
缓存的实现原理如下图所示: 缓存的实现原理如下图所示:
![cache design](https://raw.github.com/lunny/xorm/master/docs/cache_design.png) ![cache design](https://raw.github.com/go-xorm/xorm/master/docs/cache_design.png)
<a name="125" id="125"></a> <a name="125" id="125"></a>
## 12.事件 ## 12.事件
@ -788,12 +788,12 @@ xorm支持两种方式的事件一种是在Struct中的特定方法来作为
xorm工具提供了xorm命令能够帮助做很多事情。 xorm工具提供了xorm命令能够帮助做很多事情。
### 13.1.反转命令 ### 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> <a name="140" id="140"></a>
## 14.Examples ## 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> <a name="150" id="150"></a>
## 15.案例 ## 15.案例

View File

@ -41,8 +41,8 @@ When using xorm, you can create multiple orm engines, an engine means a databse.
```Go ```Go
import ( import (
_ "github.com/go-sql-driver/mysql" _ "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") engine, err := xorm.NewEngine("mysql", "root:123@/test?charset=utf8")
defer engine.Close() defer engine.Close()
``` ```
@ -52,18 +52,18 @@ or
```Go ```Go
import ( import (
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
) )
engine, err = xorm.NewEngine("sqlite3", "./test.db") 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. Generally, you can only create one engine. Engine supports run on go rutines.
xorm supports four drivers now: 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) * MyMysql: [github.com/ziutek/mymysql/godrv](https://github.com/ziutek/mymysql/godrv)
* SQLite: [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) * 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. 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.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> <a name="20" id="20"></a>
## 2.Define struct ## 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中的关键字均不区分大小写字段名区分大小写 具体的映射规则如下另Tag中的关键字均不区分大小写字段名区分大小写
@ -162,7 +162,7 @@ type User struct {
<td>pk</td><td>是否是Primary Key当前仅支持int64类型</td> <td>pk</td><td>是否是Primary Key当前仅支持int64类型</td>
</tr> </tr>
<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>
<tr> <tr>
<td>autoincr</td><td>是否是自增</td> <td>autoincr</td><td>是否是自增</td>
@ -216,7 +216,7 @@ type Conversion interface {
FromDB([]byte) error FromDB([]byte) error
ToDB() ([]byte, error) ToDB() ([]byte, error)
} }
``` ```
<a name="30" id="30"></a> <a name="30" id="30"></a>
## 3.表结构操作 ## 3.表结构操作
@ -264,7 +264,7 @@ xorm支持获取表结构信息通过调用`engine.DBMetas()`可以获取到
调用方法如下: 调用方法如下:
```Go ```Go
err := engine.Sync(new(User)) err := engine.Sync(new(User))
``` ```
<a name="50" id="50"></a> <a name="50" id="50"></a>
## 4.插入数据 ## 4.插入数据
@ -425,59 +425,59 @@ Having的参数字符串
当从一个struct来生成查询条件或更新字段时xorm会判断struct的field是否为0,"",nil如果为以上则不当做查询条件或者更新内容。因为bool类型只有true和false两种值因此默认所有bool类型不会作为查询条件或者更新字段。如果可以使用此方法如果默认不传参数则所有的bool字段都将会被使用如果参数不为空则参数中指定的为字段名则这些字段对应的bool值将被使用。 当从一个struct来生成查询条件或更新字段时xorm会判断struct的field是否为0,"",nil如果为以上则不当做查询条件或者更新内容。因为bool类型只有true和false两种值因此默认所有bool类型不会作为查询条件或者更新字段。如果可以使用此方法如果默认不传参数则所有的bool字段都将会被使用如果参数不为空则参数中指定的为字段名则这些字段对应的bool值将被使用。
* Cascade(bool) * Cascade(bool)
是否自动关联查询field中的数据如果struct的field也是一个struct并且映射为某个Id则可以在查询时自动调用Get方法查询出对应的数据。 是否自动关联查询field中的数据如果struct的field也是一个struct并且映射为某个Id则可以在查询时自动调用Get方法查询出对应的数据。
<a name="50" id="50"></a> <a name="50" id="50"></a>
### 5.3.Get one record ### 5.3.Get one record
Fetch a single object by user Fetch a single object by user
```Go ```Go
var user = User{Id:27} var user = User{Id:27}
has, err := engine.Get(&user) has, err := engine.Get(&user)
// or has, err := engine.Id(27).Get(&user) // or has, err := engine.Id(27).Get(&user)
var user = User{Name:"xlw"} var user = User{Name:"xlw"}
has, err := engine.Get(&user) has, err := engine.Get(&user)
``` ```
<a name="60" id="60"></a> <a name="60" id="60"></a>
### 5.4.Find ### 5.4.Find
Fetch multipe objects into a slice or a map, use Find Fetch multipe objects into a slice or a map, use Find
```Go ```Go
var everyone []Userinfo var everyone []Userinfo
err := engine.Find(&everyone) err := engine.Find(&everyone)
users := make(map[int64]Userinfo) users := make(map[int64]Userinfo)
err := engine.Find(&users) err := engine.Find(&users)
``` ```
* also you can use Where, Limit * also you can use Where, Limit
```Go ```Go
var allusers []Userinfo var allusers []Userinfo
err := engine.Where("id > ?", "3").Limit(10,20).Find(&allusers) //Get id>3 limit 10 offset 20 err := engine.Where("id > ?", "3").Limit(10,20).Find(&allusers) //Get id>3 limit 10 offset 20
``` ```
* or you can use a struct query * or you can use a struct query
```Go ```Go
var tenusers []Userinfo var tenusers []Userinfo
err := engine.Limit(10).Find(&tenusers, &Userinfo{Name:"xlw"}) //Get All Name="xlw" limit 10 offset 0 err := engine.Limit(10).Find(&tenusers, &Userinfo{Name:"xlw"}) //Get All Name="xlw" limit 10 offset 0
``` ```
* or In function * or In function
```Go ```Go
var tenusers []Userinfo var tenusers []Userinfo
err := engine.In("id", 1, 3, 5).Find(&tenusers) //Get All id in (1, 3, 5) 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 * The default will query all columns of a table. Use Cols function if you want to select some columns
```Go ```Go
var tenusers []Userinfo 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
``` ```
<a name="70" id="70"></a> <a name="70" id="70"></a>
@ -542,44 +542,44 @@ engine.Id(1).Get(&user)
engine.Id(1).Update(&user) engine.Id(1).Update(&user)
// UPDATE user SET ..., version = version + 1 WHERE id = ? AND version = ? // UPDATE user SET ..., version = version + 1 WHERE id = ? AND version = ?
``` ```
<a name="80" id="80"></a> <a name="80" id="80"></a>
## 7.Delete one or more records ## 7.Delete one or more records
Delete one or more records Delete one or more records
* delete by id * delete by id
```Go ```Go
err := engine.Id(1).Delete(&User{}) err := engine.Id(1).Delete(&User{})
``` ```
* delete by other conditions * delete by other conditions
```Go ```Go
err := engine.Delete(&User{Name:"xlw"}) err := engine.Delete(&User{Name:"xlw"})
``` ```
<a name="90" id="90"></a> <a name="90" id="90"></a>
## 8.Execute SQL query ## 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="100" id="100"></a> Of course, SQL execution is also provided.
## 9.Execute SQL command
If insert, update or delete then use Exec If select then use Query
```Go ```Go
sql = "update userinfo set username=? where id=?" sql := "select * from userinfo"
res, err := engine.Exec(sql, "xiaolun", 1) 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> <a name="110" id="110"></a>
## 10.Transaction ## 10.Transaction
@ -613,8 +613,8 @@ if err != nil {
err = session.Commit() err = session.Commit()
if err != nil { if err != nil {
return return
} }
``` ```
<a name="120" id="120"></a> <a name="120" id="120"></a>
## 11.缓存 ## 11.缓存
@ -654,19 +654,19 @@ engine.ClearCache(new(User))
Cache implement theory below: Cache implement theory below:
![cache design](https://raw.github.com/lunny/xorm/master/docs/cache_design.png) ![cache design](https://raw.github.com/go-xorm/xorm/master/docs/cache_design.png)
<a name="130" id="130"></a> <a name="130" id="130"></a>
## 12.xorm tool ## 12.xorm tool
xorm工具提供了xorm命令能够帮助做很多事情。 xorm工具提供了xorm命令能够帮助做很多事情。
### 12.1.Reverse command ### 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> <a name="140" id="140"></a>
## 13.Examples ## 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> <a name="150" id="150"></a>
## 14.Cases ## 14.Cases
@ -680,14 +680,14 @@ Please visit [xorm tool](https://github.com/lunny/xorm/tree/master/xorm)
* [VeryHour](http://veryhour.com) * [VeryHour](http://veryhour.com)
<a name="160"></a> <a name="160"></a>
## 15.FAQ ## 15.FAQ
1.How the xorm tag use both with json? 1.How the xorm tag use both with json?
Use space. Use space.
```Go ```Go
type User struct { type User struct {
Name string `json:"name" xorm:"name"` Name string `json:"name" xorm:"name"`
} }
``` ```

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
"github.com/lunny/xorm/caches" "github.com/go-xorm/xorm/caches"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )

View File

@ -3,7 +3,7 @@ package main
import ( import (
"fmt" "fmt"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os" "os"
) )

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )

View File

@ -6,7 +6,7 @@ import (
"runtime" "runtime"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )

View File

@ -6,7 +6,7 @@ import (
"runtime" "runtime"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
_ "github.com/bylevel/pq" _ "github.com/bylevel/pq"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )

View File

@ -1,2 +1,2 @@
[deps] [deps]
github.com/lunny/xorm=../ github.com/go-xorm/xorm=../

View File

@ -5,11 +5,11 @@ xorm tools is a set of tools for database operation.
## Install ## Install
`go get github.com/lunny/xorm/xorm` `go get github.com/go-xorm/xorm/xorm`
and you should install the depends below: 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) * Mysql: [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)

View File

@ -5,7 +5,7 @@ import (
"strings" "strings"
"text/template" "text/template"
"github.com/lunny/xorm/core" "github.com/go-xorm/core"
) )
var ( var (

View File

@ -8,7 +8,7 @@ import (
"strings" "strings"
"text/template" "text/template"
"github.com/lunny/xorm/core" "github.com/go-xorm/core"
) )
var ( var (

View File

@ -1,10 +1,10 @@
package main package main
import ( import (
"github.com/go-xorm/core"
"io/ioutil" "io/ioutil"
"strings" "strings"
"text/template" "text/template"
"github.com/lunny/xorm/core"
) )
type LangTmpl struct { type LangTmpl struct {

View File

@ -14,8 +14,8 @@ import (
_ "github.com/bylevel/pq" _ "github.com/bylevel/pq"
"github.com/dvirsky/go-pylog/logging" "github.com/dvirsky/go-pylog/logging"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/lunny/xorm" "github.com/go-xorm/core"
"github.com/lunny/xorm/core" "github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
_ "github.com/ziutek/mymysql/godrv" _ "github.com/ziutek/mymysql/godrv"

View File

@ -2,7 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/lunny/xorm" "github.com/go-xorm/xorm"
"strings" "strings"
) )