GOORM

25 views
Skip to first unread message

Asta Xie

unread,
Apr 29, 2012, 9:49:59 AM4/29/12
to golang...@googlegroups.com
大家好,最近自己项目写的一个小框架,基于go的ORM驱动,耦合了星星的mymysql驱动

地址https://github.com/astaxie/goorm

下面贴一些使用说明

How do we use it?

Open a database


orm := goorm.NewORM("127.0.0.1", "3306", "test", "xiemengjun", "123456", "utf8")

Change Database


orm.SelectDb("test2")  

Model a struct after a table in the db


type Person struct {
    Id int64
    Name string
    Age int64
}

Create an object and save it


var someone Person
someone.Name = "john"
someone.Age = 20

orm.Save(&someone)

Fetch a single object


var person1 Person
orm.Get(&person1, "id = ?", 3)

var person2 Person
orm.Get(&person2, 3) // this is shorthand for the version above

var person3 Person
orm.Get(&person3, "name = ?", "john") // more complex query

var person4 Person
orm.Get(&person4, "name = ? and age < ?", "john", 88) // even more complex

Fetch multiple objects


var bobs []Person
err := orm.GetAll(&bobs, "name = ?", "bob")

var everyone []Person
err := orm.GetAll(&everyone, "") // use empty string to omit "where" clause

Saving new and existing objects


person2.Name = "Jack" // an already-existing person in the database, from the example above
db.Save(&person2)

var newGuy Person
newGuy.Name = "that new guy"
newGuy.Age = 27

db.Save(&newGuy)
// newGuy.Id is suddenly valid, and he's in the database now.

Zoom.Quiet

unread,
Apr 29, 2012, 10:12:37 AM4/29/12
to golang...@googlegroups.com
great! go 内置了非常开放的模块发布机制
- 但是,和 apt/gem/npm/brew 比较
- 缺乏一种一致性的統一搜索和社会化评估渠道
这是否是个机会?

2012/4/29 Asta Xie <xieme...@gmail.com>:
> --
> 官网: http://golang-china.org/
> IRC: irc.freenode.net #golang-china
> @golangchina



--
人生苦短, Pythonic! 冗余不做,日子甭过!备份不做,十恶不赦!
俺: http://about.me/zoom.quiet
文字协议: http://creativecommons.org/licenses/by-sa/2.5/cn/
Reply all
Reply to author
Forward
0 new messages