improved docs struct

This commit is contained in:
Lunny Xiao 2014-09-11 18:03:03 +08:00
parent e19faeb670
commit 6bc97aa345
26 changed files with 1409 additions and 174 deletions

27
docs/LICENSE Normal file
View File

@ -0,0 +1,27 @@
Copyright (c) 2013 - 2014
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

19
docs/README.md Normal file
View File

@ -0,0 +1,19 @@
# What is this?
An open source project for Xorm documentation.
## How to contribute?
Fork, update and submit a pull request. No matter how big or small, your changes are welcome!
## How does it work?
Xorm Web server checks for updates to this folder and updates the main documentation automatically.
## Note
Xorm documentation is written using standard markdown syntax. Please submit your changes using the same syntax.
## License
This project is under Apache v2 License. See the [LICENSE](LICENSE) file for the full license text.

27
docs/en-US/about.md Normal file
View File

@ -0,0 +1,27 @@
# About
This manual documents aspects of Xorm.
### New to Xorm?
Read about the [Quick Start](docs/intro/quick_start.md).
### Can't find what you're looking for?
Search our [mailing list (xorm@googlegroups.com)](https://groups.google.com/forum/#!forum/xorm).
### Need help?
Send an email to the [xorm@googlegroups.com](mailto:xorm@googlegroups.com).
### Find a bug?
Open an [issue on github](https://github.com/go-xorm/xorm/issues).
### Want to be a contributor?
Fork the [documentation project](https://github.com/go-xorm/xorm/tree/master/docs), edit and pull request.
### Source code of this website?
Please visit [Xorm Web](https://github.com/go-xorm/website).

38
docs/en-US/donate.md Normal file
View File

@ -0,0 +1,38 @@
# Donation
<h4>
<b><font color="red">We will continue hard working with your huge support!</font></b>
</h4>
<h4>
<b>Donate by Paypal:</b>
<p>
<!--<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----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-----END PKCS7-----
">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>-->
</p>
</h4>
### Your donation will be used as:
- Supports the development of Beego
- Supports maintaining the communities
- Upgrade to better server
- Award the outstanding contributors
- Holds community activities and lectures
### Donation Lists (descending by donating time)
| Donated at | Donator | Amount | Contact | Comments |
| ---------------- |:---------:| --------:|:---------:| ----------------------- |
|2014-7-8 | Steven Wang | 100¥ | easykooc@gmail.com | xorm目前做得最好的orm for golang |
|2014-7-8 | 韩天峰 | 20¥ | apolov@vip.qq.com | xorm是Golang里最好用的DB库 |
|2014-7-8 | sunhongjian | 100¥ | shongjiang@gmail.com |支持开源,支持美好的事物! |
|2014-7-8 | Jimmy Kuu | 200¥ | jimmy.kuu@gmail.com |再接再厉,持续发展 |
|2014-7-8 | 张仲东 | 100¥ | GoCMS作者 |支持XORM!! |
|2014-7-8 | wangwei | 100¥ | iamjcww@gmail.com |鄙视楼下 |
|2014-7-8 | Jazz | 2¥ | 1002376560@qq.com |这个沙发必须抢 |

143
docs/en-US/intro/README.md Normal file
View File

@ -0,0 +1,143 @@
---
root: true
name: Introduction
sort: 0
---
[中文](https://github.com/go-xorm/xorm/blob/master/README_CN.md)
Xorm is a simple and powerful ORM for Go.
[![Build Status](https://drone.io/github.com/go-xorm/tests/status.png)](https://drone.io/github.com/go-xorm/tests/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
* Struct <-> Table Mapping Support
* Chainable APIs
* Transaction Support
* Both ORM and raw SQL operation Support
* Sync database schema Support
* Query Cache speed up
* Database Reverse support, See [Xorm Tool README](https://github.com/go-xorm/cmd/blob/master/README.md)
* Simple cascade loading support
* Optimistic Locking support
# Drivers Support
Drivers for Go's sql package which currently support database/sql includes:
* 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)
* Postgres: [github.com/lib/pq](https://github.com/lib/pq)
* MsSql: [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb)
* MsSql: [github.com/lunny/godbc](https://github.com/lunny/godbc)
# Changelog
* **v0.4.0 RC1**
Changes:
* moved xorm cmd to [github.com/go-xorm/cmd](github.com/go-xorm/cmd)
* refactored general DB operation a core lib at [github.com/go-xorm/core](https://github.com/go-xorm/core)
* moved tests to github.com/go-xorm/tests [github.com/go-xorm/tests](github.com/go-xorm/tests)
Improvements:
* Prepared statement cache
* Add Incr API
* Specify Timezone Location
* **v0.3.2**
Improvements:
* Add AllCols & MustCols function
* Add TableName for custom table name
Bug Fixes:
* #46
* #51
* #53
* #89
* #86
* #92
* **v0.3.1**
Features:
* Support MSSQL DB via ODBC driver ([github.com/lunny/godbc](https://github.com/lunny/godbc));
* Composite Key, using multiple pk xorm tag
* Added Row() API as alternative to Iterate() API for traversing result set, provide similar usages to sql.Rows type
* ORM struct allowed declaration of pointer builtin type as members to allow null DB fields
* Before and After Event processors
Improvements:
* Allowed int/int32/int64/uint/uint32/uint64/string as Primary Key type
* Performance improvement for Get()/Find()/Iterate()
[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/go-xorm/xorm
Or
go get github.com/go-xorm/xorm
# Documents
* [GoDoc](http://godoc.org/github.com/go-xorm/xorm)
* [GoWalker](http://gowalker.org/github.com/go-xorm/xorm)
* [Quick Start](https://github.com/go-xorm/xorm/blob/master/docs/QuickStart.md)
# Cases
* [Gorevel](http://http://gorevel.cn/) - [github.com/goofcc/gorevel](http://github.com/goofcc/gorevel)
* [Gogs](http://try.gogits.org) - [github.com/gogits/gogs](http://github.com/gogits/gogs)
* [Gowalker](http://gowalker.org) - [github.com/Unknwon/gowalker](http://github.com/Unknwon/gowalker)
* [Gobuild.io](http://gobuild.io) - [github.com/shxsun/gobuild](http://github.com/shxsun/gobuild)
* [Sudo China](http://sudochina.com) - [github.com/insionng/toropress](http://github.com/insionng/toropress)
* [Godaily](http://godaily.org) - [github.com/govc/godaily](http://github.com/govc/godaily)
* [Very Hour](http://veryhour.com/)
* [GoCMS - github.com/zzboy/GoCMS](https://github.com/zzdboy/GoCMS)
* [GoBBS - gobbs.domolo.com](http://gobbs.domolo.com/)
# Discuss
Please visit [Xorm on Google Groups](https://groups.google.com/forum/#!forum/xorm)
# Contributing
If you want to pull request, please see [CONTRIBUTING](https://github.com/go-xorm/xorm/blob/master/CONTRIBUTING.md)
# LICENSE
BSD License
[http://creativecommons.org/licenses/BSD/](http://creativecommons.org/licenses/BSD/)

12
docs/en-US/intro/cases.md Normal file
View File

@ -0,0 +1,12 @@
---
name: Cases
sort: 90
---
* [Gowalker](http://gowalker.org)source [github.com/Unknwon/gowalker](http://github.com/Unknwon/gowalker)
* [GoDaily](http://godaily.org)source [github.com/govc/godaily](http://github.com/govc/godaily)
* [Sudochina](http://sudochina.com) source [github.com/insionng/toropress](http://github.com/insionng/toropress)
* [VeryHour](http://veryhour.com)

View File

@ -1,3 +1,8 @@
---
name: Changelog
sort: 1
---
## Changelog
* **v0.4.0 RC1**
@ -52,3 +57,4 @@
* **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** : Initial release.

51
docs/en-US/intro/faq.md Normal file
View File

@ -0,0 +1,51 @@
---
name: FAQ
sort: 100
---
* How the xorm tag use both with json?
Use space.
```Go
type User struct {
Name string `json:"name" xorm:"name"`
}
```
* Does xorm support composite primary key?
Yes. You can use pk tag. All fields have tag will as one primary key by fields order on struct. When use, you can use xorm.PK{1, 2}. For example: `Id(xorm.PK{1, 2})`.
* How to use join
We can use Join() and extends tag to do join operation. For example:
type Userinfo struct {
Id int64
Name string
DetailId int64
}
type Userdetail struct {
Id int64
Gender int
}
type User struct {
Userinfo `xorm:"extends"`
Userdetail `xorm:"extends"`
}
var users = make([]User, 0)
err := engine.Table(&Userinfo{}).Join("LEFT", "userdetail", "userinfo.detail_id = userdetail.id").Find(&users)
//assert(User.Userinfo.Id != 0 && User.Userdetail.Id != 0)
Please notice that Userinfo field on User should be before Userdetail because of the order on join SQL stsatement. If the order is wrong, the same name field may be set a wrong value.
Of course, If join statment is very long, you could directly use Sql():
err := engine.Sql("select * from userinfo, userdetail where userinfo.detail_id = userdetail.id").Find(&users)
//assert(User.Userinfo.Id != 0 && User.Userdetail.Id != 0)

View File

@ -1,3 +1,8 @@
---
name: Quick Start
sort: 2
---
Quick Start
=====
@ -26,12 +31,7 @@ Quick Start
* [9.Execute SQL query](#100)
* [10.Transaction](#110)
* [11.Cache](#120)
* [12.Xorm Tool](#130)
* [12.1.Reverse command](#131)
* [13.Examples](#140)
* [14.Cases](#150)
* [15.FAQ](#160)
* [16.Discuss](#170)
<a name="10" id="10"></a>
## 1.Create ORM Engine
@ -54,7 +54,7 @@ import (
_ "github.com/mattn/go-sqlite3"
"github.com/go-xorm/xorm"
)
engine, err := xorm.NewEngine("sqlite3", "./test.db")
engine, err = xorm.NewEngine("sqlite3", "./test.db")
defer engine.Close()
```
@ -346,6 +346,7 @@ Notice: If you want to use transaction on inserting, you should use session.Begi
### 5.1. Chainable APIs for Queries, Execusions and Aggregations
Queries and Aggregations is basically formed by using `Get`, `Find`, `Count` methods, with conjunction of following chainable APIs to form conditions, grouping and ordering:
查询和统计主要使用`Get`, `Find`, `Count`三个方法。在进行查询时可以使用多个方法来形成查询条件,条件函数如下:
* Id([]interface{})
Primary Key lookup
@ -537,12 +538,13 @@ affected, err := engine.Table(new(User)).Id(id).Update(map[string]interface{}{"a
### 6.1.Optimistic Lock
To enable object optimistic lock, add 'version' tag value:
```Go
type User struct {
Id int64
Name string
Version int `xorm:"version"`
}
```
The version starts with 1 when inserted to DB. For updating make sure originated version value is used for optimistic lock check.
```Go
@ -666,75 +668,8 @@ Cache implement theory below:
![cache design](https://raw.github.com/go-xorm/xorm/master/docs/cache_design.png)
<a name="130" id="130"></a>
## 12.xorm tool
xorm commandl line tool
### 12.1.Reverse command
Please visit [xorm tool](https://github.com/go-xorm/cmd)
<a name="140" id="140"></a>
## 13.Examples
Please visit [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
* [Gowalker](http://gowalker.org)source [github.com/Unknwon/gowalker](http://github.com/Unknwon/gowalker)
* [GoDaily](http://godaily.org)source [github.com/govc/godaily](http://github.com/govc/godaily)
* [Sudochina](http://sudochina.com) source [github.com/insionng/toropress](http://github.com/insionng/toropress)
* [VeryHour](http://veryhour.com)
<a name="160"></a>
## 15.FAQ
* How the xorm tag use both with json?
Use space.
```Go
type User struct {
Name string `json:"name" xorm:"name"`
}
```
* Does xorm support composite primary key?
Yes. You can use pk tag. All fields have tag will as one primary key by fields order on struct. When use, you can use xorm.PK{1, 2}. For example: `Id(xorm.PK{1, 2})`.
* How to use join
We can use Join() and extends tag to do join operation. For example:
type Userinfo struct {
Id int64
Name string
DetailId int64
}
type Userdetail struct {
Id int64
Gender int
}
type User struct {
Userinfo `xorm:"extends"`
Userdetail `xorm:"extends"`
}
var users = make([]User, 0)
err := engine.Table(&Userinfo{}).Join("LEFT", "userdetail", "userinfo.detail_id = userdetail.id").Find(&users)
//assert(User.Userinfo.Id != 0 && User.Userdetail.Id != 0)
Please notice that Userinfo field on User should be before Userdetail because of the order on join SQL stsatement. If the order is wrong, the same name field may be set a wrong value.
Of course, If join statment is very long, you could directly use Sql():
err := engine.Sql("select * from userinfo, userdetail where userinfo.detail_id = userdetail.id").Find(&users)
//assert(User.Userinfo.Id != 0 && User.Userdetail.Id != 0)

109
docs/en-US/intro/tools.md Normal file
View File

@ -0,0 +1,109 @@
---
root: false
name: Xorm Tools
sort: 3
---
# xorm tools
xorm tools is a set of tools for database operation.
## Binary Install
If you have [got](https://github.com/gobuild/got) installed, you can install by got
```
got go-xorm/cmd/xorm
```
or you can download from [gobuild](http://gobuild.io/download/github.com/lunny/got).
## Source Install
`go get github.com/go-xorm/cmd/xorm`
and you should install the depends below:
* github.com/go-xorm/xorm
* 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)
* Postgres: [github.com/lib/pq](https://github.com/lib/pq)
* SQLite: [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3)
** For sqlite support, you need build via `go build -tags sqlite3` because of this driver ask cgo.
## Commands
All the commands below.
* **reverse** reverse a db to codes
* **shell** a general shell to operate all kinds of database
* **dump** dump database all table struct's and data to standard output
* **source** execute a sql from std in
* **driver** list all supported drivers
## Reverse
Reverse command is a tool to convert your database struct to all kinds languages of structs or classes. After you installed the tool, you can type
`xorm help reverse`
to get help
example:
sqlite:
`xorm reverse sqite3 test.db templates/goxorm`
mysql:
`xorm reverse mysql root:@/xorm_test?charset=utf8 templates/goxorm`
mymysql:
`xorm reverse mymysql xorm_test2/root/ templates/goxorm`
postgres:
`xorm reverse postgres "dbname=xorm_test sslmode=disable" templates/goxorm`
will generated go files in `./model` directory
### Template and Config
Now, xorm tool supports go and c++ two languages and have go, goxorm, c++ three of default templates. In template directory, we can put a config file to control how to generating.
````
lang=go
genJson=1
```
lang must be go or c++ now.
genJson can be 1 or 0, if 1 then the struct will have json tag.
## Shell
Shell command provides a tool to operate database. For example, you can create table, alter table, insert data, delete data and etc.
`xorm shell sqlite3 test.db` will connect to the sqlite3 database and you can type `help` to list all the shell commands.
## Dump
Dump command provides a tool to dump all database structs and data as SQL to your standard output.
`xorm dump sqlite3 test.db` could dump sqlite3 database test.db to standard output. If you want to save to file, just
type `xorm dump sqlite3 test.db > test.sql`.
## Source
`xorm source sqlite3 test.db < test.sql` will execute sql file on the test.db.
## Driver
List all supported drivers since default build will not include sqlite3.
## LICENSE
BSD License
[http://creativecommons.org/licenses/BSD/](http://creativecommons.org/licenses/BSD/)

22
docs/en-US/team.md Normal file
View File

@ -0,0 +1,22 @@
# Developer Team
### Unknown
- Team role: Project manager, back-end developer.
- Social network: [Sina Weibo](http://weibo.com/Obahua) [GitHub](https://github.com/Unknwon) [Twitter](https://twitter.com/joe2010xtmf) [Google+](https://plus.google.com/u/0/+JiahuaChen)
### Lunny
- Team role: Back-end Git and database developer.
- Social network: [Sina Weibo](http://weibo.com/xiaolunwen) [GitHub](https://github.com/lunny) [Twitter](https://twitter.com/lunny)
### Fuxiaohei
- Team role: Front-end developer.
- Social network: [Sina Weibo](http://weibo.com/fuxiaohei) [GitHub](https://github.com/fuxiaohei)
### Slene
- Team role: Front and back-end developer.
- Social network: [Sina Weibo](http://weibo.com/slene) [GitHub](https://github.com/slene) [Twitter](https://twitter.com/slene)

View File

Before

Width:  |  Height:  |  Size: 238 KiB

After

Width:  |  Height:  |  Size: 238 KiB

27
docs/zh-CN/about.md Normal file
View File

@ -0,0 +1,27 @@
# 关于
本网站文档页面详细描述了 Xorm 的各个方面。
### 新手指导
如果您是首次了解 Xorm我们建议您先阅读 [快速入门](docs/intro/quick_start.md)。
### 其它资源
如果您无法找到相关问题的满意答案,可以在 [邮件列表 (xorm@googlegroups.com)](https://groups.google.com/forum/#!search/xorm) 中搜索。
### 寻求帮助
如果您遇到无法解决的问题,可以发送邮件到 [xorm@googlegroups.com](mailto:xorm@googlegroups.com) 提问。
### 问题提交
如果您在使用过程中发现 Xorm 有潜在的问题,请通过 [Xorm](https://github.com/go-xorm/xorm/issues) 上的问题列表提交。
### 完善文档
您可以通过派生 [文档项目](https://github.com/go-xorm/xorm/tree/master/docs)、编辑,然后提交合并请求。
### 网站源码
请移步 [Xorm Web](https://github.com/go-xorm/website)。

44
docs/zh-CN/donate.md Normal file
View File

@ -0,0 +1,44 @@
# 捐赠我们
<h4>
<b><font color="red">在您的支持与鼓励下Xorm 开发团队将会更加努力地开发出更好的产品!</font></b>
</h4>
<h4>
<b>支付宝捐赠</b>
</h4>
<img src="/img/alipay.png"/>
<h4>
<b>Paypal 捐赠</b>
<p>
<!--<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----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-----END PKCS7-----
">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>-->
</p>
</h4>
### 您的捐赠将被用于:
- 持续和深入的开发
- 维护社区的运行稳定
- 租用更好的带宽
- 奖励团队的杰出贡献者
- 社区活动或讲座
### 捐赠列表(按照捐赠时间倒序)
| 捐赠时间 | 捐赠人 | 金额 | 联系方式 | 附言 |
| ---------------- |:---------:| --------:|:---------:| ----------------------- |
|2014-7-8 | Steven Wang | 100¥ | easykooc@gmail.com | xorm目前做得最好的orm for golang |
|2014-7-8 | 韩天峰 | 20¥ | apolov@vip.qq.com | xorm是Golang里最好用的DB库 |
|2014-7-8 | sunhongjian | 100¥ | shongjiang@gmail.com |支持开源,支持美好的事物! |
|2014-7-8 | Jimmy Kuu | 200¥ | jimmy.kuu@gmail.com |再接再厉,持续发展 |
|2014-7-8 | 张仲东 | 100¥ | GoCMS作者 |支持XORM!! |
|2014-7-8 | wangwei | 100¥ | iamjcww@gmail.com |鄙视楼下 |
|2014-7-8 | Jazz | 2¥ | 1002376560@qq.com |这个沙发必须抢 |

View File

@ -0,0 +1,65 @@
When a struct auto mapping to a database's table, the below table describes how they change to each other:
<table>
<tr>
<td>go type's kind
</td>
<td>value method</td>
<td>xorm type
</td>
</tr>
<tr>
<td>implemented Conversion</td>
<td>Conversion.ToDB / Conversion.FromDB</td>
<td>Text</td>
</tr>
<tr>
<td>int, int8, int16, int32, uint, uint8, uint16, uint32</td>
<td></td>
<td> Int </td>
</tr>
<tr>
<td>int64, uint64</td><td></td><td>BigInt</td>
</tr>
<tr><td>float32</td><td></td><td>Float</td>
</tr>
<tr><td>float64</td><td></td><td>Double</td>
</tr>
<tr><td>complex64, complex128</td>
<td>json.Marshal / json.UnMarshal</td>
<td>Varchar(64)</td>
</tr>
<tr>
<td>[]uint8</td><td></td><td>Blob</td>
</tr>
<tr>
<td>array, slice, map except []uint8</td>
<td>json.Marshal / json.UnMarshal</td>
<td>Text</td>
</tr>
<tr>
<td>bool</td><td>1 or 0</td><td>Bool</td>
</tr>
<tr>
<td>string</td><td></td><td>Varchar(255)</td>
</tr>
<tr>
<td>time.Time</td><td></td><td>DateTime</td>
</tr>
<tr>
<td>cascade struct</td><td>primary key field value</td><td>BigInt</td>
</tr>
<tr>
<tr>
<td>struct</td><td>json.Marshal / json.UnMarshal</td><td>Text</td>
</tr>
<tr>
<td>
Others
</td>
<td></td>
<td>
Text
</td>
</tr>
</table>

View File

@ -0,0 +1,438 @@
<table>
<tr>
<td>xorm
</td>
<td>mysql
</td>
<td>sqlite3
</td>
<td>postgres
</td>
<td>remark</td>
</tr>
<tr>
<td>BIT
</td>
<td>BIT
</td>
<td>INTEGER
</td>
<td>BIT
</td>
<td></td>
</tr>
<tr>
<td>TINYINT
</td>
<td>TINYINT
</td>
<td>INTEGER
</td>
<td>SMALLINT
</td>
<td></td>
</tr>
<tr>
<td>SMALLINT
</td>
<td>SMALLINT
</td>
<td>INTEGER
</td>
<td>SMALLINT
</td>
<td></td>
</tr>
<tr>
<td>MEDIUMINT
</td>
<td>MEDIUMINT
</td>
<td>INTEGER
</td>
<td>INTEGER
</td>
<td></td>
</tr>
<tr>
<td>INT
</td>
<td>INT
</td>
<td>INTEGER
</td>
<td>INTEGER
</td>
<td></td>
</tr>
<tr>
<td>INTEGER
</td>
<td>INTEGER
</td>
<td>INTEGER
</td>
<td>INTEGER
</td>
<td></td>
</tr>
<tr>
<td>BIGINT
</td>
<td>BIGINT
</td>
<td>INTEGER
</td>
<td>BIGINT
</td>
<td></td>
</tr>
<tr><td cols="5"></td></tr>
<tr>
<td>CHAR
</td>
<td>CHAR
</td>
<td>TEXT
</td>
<td>CHAR
</td>
<td></td>
</tr>
<tr>
<td>VARCHAR
</td>
<td>VARCHAR
</td>
<td>TEXT
</td>
<td>VARCHAR
</td>
<td></td>
</tr>
<tr>
<td>TINYTEXT
</td>
<td>TINYTEXT
</td>
<td>TEXT
</td>
<td>TEXT
</td>
<td></td>
</tr>
<tr>
<td>TEXT
</td>
<td>TEXT
</td>
<td>TEXT
</td>
<td>TEXT
</td>
<td></td>
</tr>
<tr>
<td>MEDIUMTEXT
</td>
<td>MEDIUMTEXT
</td>
<td>TEXT
</td>
<td>TEXT
</td>
<td></td>
</tr>
<tr>
<td>LONGTEXT
</td>
<td>LONGTEXT
</td>
<td>TEXT
</td>
<td>TEXT
</td>
<td></td>
</tr>
<tr><td cols="5"></td></tr>
<tr>
<td>BINARY
</td>
<td>BINARY
</td>
<td>BLOB
</td>
<td>BYTEA
</td>
<td></td>
</tr>
<tr>
<td>VARBINARY
</td>
<td>VARBINARY
</td>
<td>BLOB
</td>
<td>BYTEA
</td>
<td></td>
</tr>
<tr><td cols="5"></td></tr>
<tr>
<td>DATE
</td>
<td>DATE
</td>
<td>NUMERIC
</td>
<td>DATE
</td>
<td></td>
</tr>
<tr>
<td>DATETIME
</td>
<td>DATETIME
</td>
<td>NUMERIC
</td>
<td>TIMESTAMP
</td>
<td></td>
</tr>
<tr>
<td>TIME
</td>
<td>TIME
</td>
<td>NUMERIC
</td>
<td>TIME
</td>
<td></td>
</tr>
<tr>
<td>TIMESTAMP
</td>
<td>TIMESTAMP
</td>
<td>NUMERIC
</td>
<td>TIMESTAMP
</td>
<td></td>
</tr>
<tr>
<td>TIMESTAMPZ
</td>
<td>TEXT
</td>
<td>TEXT
</td>
<td>TIMESTAMP with zone
</td>
<td>timestamp with zone info</td>
</tr>
<tr><td cols="5"></td></tr>
<tr>
<td>REAL
</td>
<td>REAL
</td>
<td>REAL
</td>
<td>REAL
</td>
<td></td>
</tr>
<tr>
<td>FLOAT
</td>
<td>FLOAT
</td>
<td>REAL
</td>
<td>REAL
</td>
<td></td>
</tr>
<tr>
<td>DOUBLE
</td>
<td>DOUBLE
</td>
<td>REAL
</td>
<td>DOUBLE PRECISION
</td>
<td></td>
</tr>
<tr><td cols="5"></td></tr>
<tr>
<td>DECIMAL
</td>
<td>DECIMAL
</td>
<td>NUMERIC
</td>
<td>DECIMAL
</td>
<td></td>
</tr>
<tr>
<td>NUMERIC
</td>
<td>NUMERIC
</td>
<td>NUMERIC
</td>
<td>NUMERIC
</td>
<td></td>
</tr>
<tr><td cols="5"></td></tr>
<tr>
<td>TINYBLOB
</td>
<td>TINYBLOB
</td>
<td>BLOB
</td>
<td>BYTEA
</td>
<td></td>
</tr>
<tr>
<td>BLOB
</td>
<td>BLOB
</td>
<td>BLOB
</td>
<td>BYTEA
</td>
<td></td>
</tr>
<tr>
<td>MEDIUMBLOB
</td>
<td>MEDIUMBLOB
</td>
<td>BLOB
</td>
<td>BYTEA
</td>
<td></td>
</tr>
<tr>
<td>LONGBLOB
</td>
<td>LONGBLOB
</td>
<td>BLOB
</td>
<td>BYTEA
</td>
<td></td>
</tr>
<tr>
<td>BYTEA
</td>
<td>BLOB
</td>
<td>BLOB
</td>
<td>BYTEA
</td>
<td></td>
</tr>
<tr><td cols="5"></td></tr>
<tr>
<td>BOOL
</td>
<td>TINYINT
</td>
<td>INTEGER
</td>
<td>BOOLEAN
</td>
<td></td>
</tr>
<tr>
<td>SERIAL
</td>
<td>INT
</td>
<td>INTEGER
</td>
<td>SERIAL
</td>
<td>auto increment</td>
</tr>
<tr>
<td>BIGSERIAL
</td>
<td>BIGINT
</td>
<td>INTEGER
</td>
<td>BIGSERIAL
</td>
<td>auto increment</td>
</tr>
</table>

143
docs/zh-CN/intro/README.md Normal file
View File

@ -0,0 +1,143 @@
---
root: true
name: 简介
sort: 0
---
# xorm
[English](https://github.com/go-xorm/xorm/blob/master/README.md)
xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作非常简便。
[![Build Status](https://drone.io/github.com/go-xorm/tests/status.png)](https://drone.io/github.com/go-xorm/tests/latest) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/go-xorm/xorm)
## 特性
* 支持Struct和数据库表之间的灵活映射并支持自动同步
* 事务支持
* 同时支持原始SQL语句和ORM操作的混合执行
* 使用连写来简化调用
* 支持使用Id, In, Where, Limit, Join, Having, Table, Sql, Cols等函数和结构体等方式作为条件
* 支持级联加载Struct
* 支持缓存
* 支持根据数据库自动生成xorm的结构体
* 支持记录版本(即乐观锁)
## 驱动支持
目前支持的Go数据库驱动和对应的数据库如下
* 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)
* Postgres: [github.com/lib/pq](https://github.com/lib/pq)
* MsSql: [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb)
* MsSql: [github.com/lunny/godbc](https://github.com/lunny/godbc)
## 更新日志
* **v0.4.0 RC1**
新特性:
* 移动xorm cmd [github.com/go-xorm/cmd](github.com/go-xorm/cmd)
* 在重构一般DB操作核心库 [github.com/go-xorm/core](https://github.com/go-xorm/core)
* 移动测试github.com/复XORM/测试 [github.com/go-xorm/tests](github.com/go-xorm/tests)
改进:
* Prepared statement 缓存
* 添加 Incr API
* 指定时区位置
* **v0.3.2**
新特性:
* Add AllCols & MustCols function
* Add TableName for custom table name
Bug 修复:
* #46
* #51
* #53
* #89
* #86
* #92
* **v0.3.1**
新特性:
* 支持 MSSQL DB 通过 ODBC 驱动 ([github.com/lunny/godbc](https://github.com/lunny/godbc));
* 通过多个pk标记支持联合主键;
* 新增 Rows() API 用来遍历查询结果该函数提供了类似sql.Rows的相似用法可作为 Iterate() API 的可选替代;
* ORM 结构体现在允许内建类型的指针作为成员使得数据库为null成为可能
* Before 和 After 支持
改进:
* 允许 int/int32/int64/uint/uint32/uint64/string 作为主键类型
* 查询函数 Get()/Find()/Iterate() 在性能上的改进
[更多更新日志...](https://github.com/go-xorm/xorm/blob/master/docs/ChangelogCN.md)
## 安装
推荐使用 [gopm](https://github.com/gpmgo/gopm) 进行安装:
gopm get github.com/go-xorm/xorm
或者您也可以使用go工具进行安装
go get github.com/go-xorm/xorm
## 文档
* [快速开始](https://github.com/go-xorm/xorm/blob/master/docs/QuickStartCN.md)
* [GoWalker代码文档](http://gowalker.org/github.com/go-xorm/xorm)
* [Godoc代码文档](http://godoc.org/github.com/go-xorm/xorm)
## 案例
* [Gogs](http://try.gogits.org) - [github.com/gogits/gogs](http://github.com/gogits/gogs)
* [Gowalker](http://gowalker.org) - [github.com/Unknwon/gowalker](http://github.com/Unknwon/gowalker)
* [Gobuild.io](http://gobuild.io) - [github.com/shxsun/gobuild](http://github.com/shxsun/gobuild)
* [Sudo China](http://sudochina.com) - [github.com/insionng/toropress](http://github.com/insionng/toropress)
* [Godaily](http://godaily.org) - [github.com/govc/godaily](http://github.com/govc/godaily)
* [Very Hour](http://veryhour.com/)
* [GoCMS - github.com/zzboy/GoCMS](https://github.com/zzdboy/GoCMS)
* [GoBBS - gobbs.domolo.com](http://gobbs.domolo.com/)
## 讨论
请加入QQ群280360085 进行讨论。
## 贡献
如果您也想为Xorm贡献您的力量请查看 [CONTRIBUTING](https://github.com/go-xorm/xorm/blob/master/CONTRIBUTING.md)
## LICENSE
BSD License
[http://creativecommons.org/licenses/BSD/](http://creativecommons.org/licenses/BSD/)

13
docs/zh-CN/intro/cases.md Normal file
View File

@ -0,0 +1,13 @@
---
name: 案例
sort: 90
---
* [Gowalker](http://gowalker.org),源代码 [github.com/Unknwon/gowalker](http://github.com/Unknwon/gowalker)
* [GoDaily Go语言学习网站](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)
* [VeryHour](http://veryhour.com)

View File

@ -1,3 +1,8 @@
---
name: 变更日志
sort: 1
---
## 更新日志
* **v0.4.0 RC1**

74
docs/zh-CN/intro/faq.md Normal file
View File

@ -0,0 +1,74 @@
---
name: FAQ
sort: 100
---
* 怎么同时使用xorm的tag和json的tag
答:使用空格
```Go
type User struct {
Name string `json:"name" xorm:"name"`
}
```
* 我的struct里面包含bool类型为什么它不能作为条件也没法用Update更新
默认bool类型因为无法判断是否为空所以不会自动作为条件也不会作为Update的内容。可以使用UseBool函数也可以使用Cols函数
```Go
engine.Cols("bool_field").Update(&Struct{BoolField:true})
// UPDATE struct SET bool_field = true
```
* 我的struct里面包含float64和float32类型为什么用他们作为查询条件总是不正确
默认float32和float64映射到数据库中为float,real,double这几种类型这几种数据库类型数据库的实现一般都是非精确的。因此作为相等条件查询有可能不会返回正确的结果。如果一定要作为查询条件请将数据库中的类型定义为Numeric或者Decimal。
```Go
type account struct {
money float64 `xorm:"Numeric"`
}
```
* 为什么Update时Sqlite3返回的affected和其它数据库不一样
Sqlite3默认Update时返回的是update的查询条件的记录数条数不管记录是否真的有更新。而Mysql和Postgres默认情况下都是只返回记录中有字段改变的记录数。
* xorm有几种命名映射规则
目前支持SnakeMapper和SameMapper两种。SnakeMapper支持结构体和成员以驼峰式命名而数据库表和字段以下划线连接命名SameMapper支持结构体和数据库的命名保持一致的映射。
* xorm支持复合主键吗
支持。在定义时如果有多个字段标记了pk则这些字段自动成为复合主键顺序为在struct中出现的顺序。在使用Id方法时可以用`Id(xorm.PK{1, 2})`的方式来用。
* xorm如何使用Join
一般我们配合Join()和extends标记来进行比如我们要对两个表进行Join操作我们可以这样
type Userinfo struct {
Id int64
Name string
DetailId int64
}
type Userdetail struct {
Id int64
Gender int
}
type User struct {
Userinfo `xorm:"extends"`
Userdetail `xorm:"extends"`
}
var users = make([]User, 0)
err := engine.Table(&Userinfo{}).Join("LEFT", "userdetail", "userinfo.detail_id = userdetail.id").Find(&users)
请注意这里的Userinfo在User中的位置必须在Userdetail的前面因为他在join语句中的顺序在userdetail前面。如果顺序不对那么对于同名的列有可能会赋值出错。
当然如果Join语句比较复杂我们也可以直接用Sql函数
err := engine.Sql("select * from userinfo, userdetail where userinfo.detail_id = userdetail.id").Find(&users)

View File

@ -1,3 +1,8 @@
---
name: 快速开始
sort: 2
---
xorm 快速入门
=====
@ -30,12 +35,7 @@ xorm 快速入门
* [10.事务处理](#110)
* [11.缓存](#120)
* [12.事件](#125)
* [13.xorm工具](#130)
* [13.1.反转命令](#131)
* [14.Examples](#140)
* [15.案例](#150)
* [16.那些年我们踩过的坑](#160)
* [17.讨论](#170)
<a name="10" id="10"></a>
## 1.创建Orm引擎
@ -58,7 +58,7 @@ import (
_ "github.com/mattn/go-sqlite3"
"github.com/go-xorm/xorm"
)
engine, err := xorm.NewEngine("sqlite3", "./test.db")
engine, err = xorm.NewEngine("sqlite3", "./test.db")
defer engine.Close()
```
@ -764,101 +764,7 @@ xorm支持两种方式的事件一种是在Struct中的特定方法来作为
其中beforeFunc和afterFunc的原型为func(bean interface{}).
<a name="130" id="130"></a>
## 13.xorm工具
xorm工具提供了xorm命令能够帮助做很多事情。
### 13.1.反转命令
参见 [xorm工具](https://github.com/go-xorm/cmd)
<a name="140" id="140"></a>
## 14.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.案例
* [Gowalker](http://gowalker.org),源代码 [github.com/Unknwon/gowalker](http://github.com/Unknwon/gowalker)
* [GoDaily Go语言学习网站](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)
* [VeryHour](http://veryhour.com)
<a name="160" id="160"></a>
## 16.那些年我们踩过的坑
* 怎么同时使用xorm的tag和json的tag
答:使用空格
```Go
type User struct {
Name string `json:"name" xorm:"name"`
}
```
* 我的struct里面包含bool类型为什么它不能作为条件也没法用Update更新
默认bool类型因为无法判断是否为空所以不会自动作为条件也不会作为Update的内容。可以使用UseBool函数也可以使用Cols函数
```Go
engine.Cols("bool_field").Update(&Struct{BoolField:true})
// UPDATE struct SET bool_field = true
```
* 我的struct里面包含float64和float32类型为什么用他们作为查询条件总是不正确
默认float32和float64映射到数据库中为float,real,double这几种类型这几种数据库类型数据库的实现一般都是非精确的。因此作为相等条件查询有可能不会返回正确的结果。如果一定要作为查询条件请将数据库中的类型定义为Numeric或者Decimal。
```Go
type account struct {
money float64 `xorm:"Numeric"`
}
```
* 为什么Update时Sqlite3返回的affected和其它数据库不一样
Sqlite3默认Update时返回的是update的查询条件的记录数条数不管记录是否真的有更新。而Mysql和Postgres默认情况下都是只返回记录中有字段改变的记录数。
* xorm有几种命名映射规则
目前支持SnakeMapper和SameMapper两种。SnakeMapper支持结构体和成员以驼峰式命名而数据库表和字段以下划线连接命名SameMapper支持结构体和数据库的命名保持一致的映射。
* xorm支持复合主键吗
支持。在定义时如果有多个字段标记了pk则这些字段自动成为复合主键顺序为在struct中出现的顺序。在使用Id方法时可以用`Id(xorm.PK{1, 2})`的方式来用。
* xorm如何使用Join
一般我们配合Join()和extends标记来进行比如我们要对两个表进行Join操作我们可以这样
type Userinfo struct {
Id int64
Name string
DetailId int64
}
type Userdetail struct {
Id int64
Gender int
}
type User struct {
Userinfo `xorm:"extends"`
Userdetail `xorm:"extends"`
}
var users = make([]User, 0)
err := engine.Table(&Userinfo{}).Join("LEFT", "userdetail", "userinfo.detail_id = userdetail.id").Find(&users)
请注意这里的Userinfo在User中的位置必须在Userdetail的前面因为他在join语句中的顺序在userdetail前面。如果顺序不对那么对于同名的列有可能会赋值出错。
当然如果Join语句比较复杂我们也可以直接用Sql函数
err := engine.Sql("select * from userinfo, userdetail where userinfo.detail_id = userdetail.id").Find(&users)
<a name="170" id="170"></a>
## 17.讨论
请加入QQ群280360085 进行讨论。

109
docs/zh-CN/intro/tools.md Normal file
View File

@ -0,0 +1,109 @@
---
root: false
name: xorm 工具
sort: 3
---
# xorm 工具
xorm 是一组数据库操作命令行工具。
## 二进制安装
如果你安装了 [got](https://github.com/gobuild/got),你可以输入如下命令安装:
```
got go-xorm/cmd/xorm
```
或者你可以从 [gobuild](http://gobuild.io/download/github.com/lunny/got) 下载后解压到可执行路径。
## 源码安装
`go get github.com/go-xorm/cmd/xorm`
同时你需要安装如下依赖:
* github.com/go-xorm/xorm
* 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)
* Postgres: [github.com/lib/pq](https://github.com/lib/pq)
* SQLite: [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3)
** 对于sqlite3的支持你需要自己进行编译 `go build -tags sqlite3` 因为sqlite3需要cgo的支持。
## 命令列表
有如下可用的命令:
* **reverse** 反转一个数据库结构,生成代码
* **shell** 通用的数据库操作客户端,可对数据库结构和数据操作
* **dump** Dump数据库中所有结构和数据到标准输出
* **source** 从标注输入中执行SQL文件
* **driver** 列出所有支持的数据库驱动
## reverse
Reverse command is a tool to convert your database struct to all kinds languages of structs or classes. After you installed the tool, you can type
`xorm help reverse`
to get help
example:
sqlite:
`xorm reverse sqite3 test.db templates/goxorm`
mysql:
`xorm reverse mysql root:@/xorm_test?charset=utf8 templates/goxorm`
mymysql:
`xorm reverse mymysql xorm_test2/root/ templates/goxorm`
postgres:
`xorm reverse postgres "dbname=xorm_test sslmode=disable" templates/goxorm`
will generated go files in `./model` directory
### Template and Config
Now, xorm tool supports go and c++ two languages and have go, goxorm, c++ three of default templates. In template directory, we can put a config file to control how to generating.
````
lang=go
genJson=1
```
lang must be go or c++ now.
genJson can be 1 or 0, if 1 then the struct will have json tag.
## Shell
Shell command provides a tool to operate database. For example, you can create table, alter table, insert data, delete data and etc.
`xorm shell sqlite3 test.db` will connect to the sqlite3 database and you can type `help` to list all the shell commands.
## Dump
Dump command provides a tool to dump all database structs and data as SQL to your standard output.
`xorm dump sqlite3 test.db` could dump sqlite3 database test.db to standard output. If you want to save to file, just
type `xorm dump sqlite3 test.db > test.sql`.
## Source
`xorm source sqlite3 test.db < test.sql` will execute sql file on the test.db.
## Driver
List all supported drivers since default build will not include sqlite3.
## LICENSE
BSD License
[http://creativecommons.org/licenses/BSD/](http://creativecommons.org/licenses/BSD/)

22
docs/zh-CN/team.md Normal file
View File

@ -0,0 +1,22 @@
# 开发者团队
### 无闻
- 团队角色:项目管理员,后端开发者
- 社交网络:[新浪微博](http://weibo.com/Obahua) [GitHub](https://github.com/Unknwon) [Twitter](https://twitter.com/joe2010xtmf) [Google+](https://plus.google.com/u/0/+JiahuaChen)
### Lunny
- 团队角色:后端 Git 和数据库部分开发者
- 社交网络:[新浪微博](http://weibo.com/xiaolunwen) [GitHub](https://github.com/lunny) [Twitter](https://twitter.com/lunny)
### 傅小黑
- 团队角色:前端开发者
- 社交网络:[新浪微博](http://weibo.com/fuxiaohei) [GitHub](https://github.com/fuxiaohei)
### Slene
- 团队角色:前、后端开发者
- 社交网络:[新浪微博](http://weibo.com/slene) [GitHub](https://github.com/slene) [Twitter](https://twitter.com/slene)