improved docs

This commit is contained in:
Lunny Xiao 2014-05-23 14:45:49 +08:00
parent e4f05916cb
commit 929df107f1
3 changed files with 63 additions and 2 deletions

View File

@ -4,7 +4,7 @@
新特性: 新特性:
* 移动xorm cmd [github.com/go-xorm/cmd](github.com/go-xorm/cmd) * 移动xorm cmd [github.com/go-xorm/cmd](github.com/go-xorm/cmd)
* 在重构一般DB操作核心库 [github.com/go-xorm/core](https://github.com/go-xorm/core) * 在重构一般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) * 移动测试github.com/XORM/tests [github.com/go-xorm/tests](github.com/go-xorm/tests)
改进: 改进:
* Prepared statement 缓存 * Prepared statement 缓存

View File

@ -693,7 +693,7 @@ Please visit [https://github.com/go-xorm/xorm/tree/master/examples](https://gith
<a name="160"></a> <a name="160"></a>
## 15.FAQ ## 15.FAQ
1.How the xorm tag use both with json? * How the xorm tag use both with json?
Use space. Use space.
@ -702,3 +702,38 @@ type User struct {
Name string `json:"name" xorm:"name"` 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)
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

@ -830,6 +830,32 @@ money float64 `xorm:"Numeric"`
支持。在定义时如果有多个字段标记了pk则这些字段自动成为复合主键顺序为在struct中出现的顺序。在使用Id方法时可以用`Id(xorm.PK{1, 2})`的方式来用。 支持。在定义时如果有多个字段标记了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)
当然如果Join语句比较复杂我们也可以直接用Sql函数
err := engine.Sql("select * from userinfo, userdetail where userinfo.detail_id = userdetail.id").Find(&users)
<a name="170" id="170"></a> <a name="170" id="170"></a>
## 17.讨论 ## 17.讨论