Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit

Permalink
Improved documents; Optimistic Locking support; Timestamp with time z…
Browse files Browse the repository at this point in the history
…one 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;
  • Loading branch information
lunny committed Nov 29, 2013
1 parent 20bfc62 commit cc0ce11
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Xorm is a simple and powerful ORM for Go.
* Database Reverse support, See [Xorm Tool README](https://github.com/lunny/xorm/blob/master/xorm/README.md)

* Simple cascade loading support

* Optimistic Locking support


# Drivers Support

Expand All @@ -37,6 +40,7 @@ Drivers for Go's sql package which currently support database/sql includes:

# Changelog

* **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;
Expand Down
3 changes: 3 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作

* 支持根据数据库自动生成xorm的结构体

* 支持记录版本(即乐观锁)

## 驱动支持

目前支持的Go数据库驱动如下:
Expand All @@ -39,6 +41,7 @@ xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作
* Postgres: [github.com/bylevel/pq](https://github.com/bylevel/pq)

## 更新日志
* **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同步表结构;
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
xorm v0.2.2
xorm v0.2.3
4 changes: 2 additions & 2 deletions base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ type Version struct {
}

func testVersion(engine *Engine, t *testing.T) {
/*err := engine.DropTables(new(Version))
err := engine.DropTables(new(Version))
if err != nil {
t.Error(err)
panic(err)
Expand Down Expand Up @@ -1507,7 +1507,7 @@ func testVersion(engine *Engine, t *testing.T) {
err = errors.New("insert error")
t.Error(err)
panic(err)
}*/
}

/*
newVer.Name = "-------"
Expand Down
24 changes: 24 additions & 0 deletions docs/QuickStart.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ xorm 快速入门
* [5.5.Iterate方法](#65)
* [5.6.Count方法](#66)
* [6.更新数据](#70)
* [6.1.乐观锁](#71)
* [7.删除数据](#80)
* [8.执行SQL查询](#90)
* [9.执行SQL命令](#100)
Expand Down Expand Up @@ -176,6 +177,9 @@ type User struct {
</tr>
<tr>
<td>updated</td><td>这个Field将在Insert或Update时自动赋值为当前时间</td>
</tr>
<tr>
<td>version</td><td>这个Field将会在insert时默认为1,每次更新自动加1</td>
</tr>
<tr>
<td>default 0</td><td>设置默认值,紧跟的内容如果是Varchar等需要加上单引号</td>
Expand Down Expand Up @@ -518,6 +522,26 @@ affected, err := engine.Id(id).Cols("age").Update(&user)
affected, err := engine.Table(new(User)).Id(id).Update(map[string]interface{}{"age":0})
```

<a name="71" id="71"></a>
### 6.1.乐观锁

要使用乐观锁,需要使用version标记
type User struct {
Id int64
Name string
Version int `xorm:"version"`
}

在Insert时,version标记的字段将会被设置为1,在Update时,Update的内容必须包含version原来的值。

```Go
var user User
engine.Id(1).Get(&user)
// SELECT * FROM user WHERE id = ?
engine.Id(1).Update(&user)
// UPDATE user SET ..., version = version + 1 WHERE id = ? AND version = ?
```

<a name="80" id="80"></a>
## 7.删除数据

Expand Down
31 changes: 28 additions & 3 deletions docs/QuickStartEn.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Quick Start
* [5.5.Iterate](#65)
* [5.6.Count](#66)
* [6.Update records](#70)
* [6.1.Optimistic Locking](#71)
* [7.Delete records](#80)
* [8.Execute SQL command](#90)
* [9.Execute SQL query](#100)
Expand Down Expand Up @@ -171,10 +172,13 @@ type User struct {
<td>&lt;-</td><td>这个Field将只从数据库读取,而不写入到数据库</td>
</tr>
<tr>
<td>created</td><td>这个Field将在Insert时自动赋值为当前时间</td>
<td>created</td><td>This field will be filled in current time on insert</td>
</tr>
<tr>
<td>updated</td><td>这个Field将在Insert或Update时自动赋值为当前时间</td>
<td>updated</td><td>This field will be filled in current time on insert or update</td>
</tr>
<tr>
<td>version</td><td>This field will be filled 1 on insert and autoincrement on update</td>
</tr>
<tr>
<td>default 0</td><td>设置默认值,紧跟的内容如果是Varchar等需要加上单引号</td>
Expand Down Expand Up @@ -500,7 +504,28 @@ affected, err := engine.Id(id).Cols("age").Update(&user)
2. 通过传入map[string]interface{}来进行更新,但这时需要额外指定更新到哪个表,因为通过map是无法自动检测更新哪个表的。
```Go
affected, err := engine.Table(new(User)).Id(id).Update(map[string]interface{}{"age":0})
```
```


### 6.1.乐观锁

要使用乐观锁,需要使用version标记
type User struct {
Id int64
Name string
Version int `xorm:"version"`
}

在Insert时,version标记的字段将会被设置为1,在Update时,Update的内容必须包含version原来的值。

```Go
var user User
engine.Id(1).Get(&user)
// SELECT * FROM user WHERE id = ?
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
Expand Down
4 changes: 3 additions & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,9 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
}

if table.Cacher != nil && session.Statement.UseCache {
session.cacheUpdate(sql, args...)
//session.cacheUpdate(sql, args...)
table.Cacher.ClearIds(session.Statement.TableName())
table.Cacher.ClearBeans(session.Statement.TableName())
}

return res.RowsAffected()
Expand Down

0 comments on commit cc0ce11

Please sign in to comment.