xorm速记卡 Quick Reference

links

  • github: https://github.com/go-xorm/xorm

  • godoc: http://godoc.org/github.com/go-xorm/xorm

  • gowalker: https://gowalker.org/github.com/go-xorm/xorm

  • quickstart: https://github.com/lunny/xorm/blob/master/docs/QuickStartEn.md

    install

    go get -v github.com/go-xorm/xorm

usage

x, err := xorm.NewEngine(“mysql”, “root:123@/test?charset=utf8”)
defer x.Close()

driver and source

mysql github.com/go-sql-driver/mysql

[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]

mymysql github.com/ziutek/mymysql/godrv

usage todo.

postgresql github.com/lib/pq

1. postgres://username:password@address/dbname?sslmode=verify-full
2. user=pqgotest dbname=pqgotest sslmode=verify-full

column types

ref: https://github.com/lunny/xorm/blob/master/docs/COLUMNTYPE.md

  • pk # primary key
  • autoincr
  • [not ]null
  • unique or unique(uniquename)
  • index or index(indexname)
  • extends
  • `- # ignore this field
  • created # This field will be filled in current time on insert
  • version # This field will be filled 1 on insert and autoincrement on update
  • default 0 # default value, need quoted if it is a string

common func and CRUD funcs

// create user table
err := engine.Sync(new(User))

INSERT (Create) more

user := new(User)
user.Name = "myname"
affected, err := x.Insert(user)

Query (Retrieve) more

err = x.Cols("age", "name").Limit(10).Find(&users)

Update (Update) more

你可能感兴趣的:(xorm速记卡 Quick Reference)