1
0
Fork 0
forked from forgejo/forgejo

fix migrate failed and org dashboard failed on MSSQL database (#1448)

This commit is contained in:
Lunny Xiao 2017-04-06 18:47:25 -07:00 committed by GitHub
parent cf6699fb4f
commit 5acfc7c4bc
36 changed files with 1999 additions and 1634 deletions

View file

@ -24,7 +24,7 @@ Generally, one engine for an application is enough. You can set it as package va
Raw Methods
Xorm also support raw sql execution:
XORM also support raw SQL execution:
1. query a SQL string, the returned results is []map[string][]byte
@ -36,7 +36,7 @@ Xorm also support raw sql execution:
ORM Methods
There are 7 major ORM methods and many helpful methods to use to operate database.
There are 8 major ORM methods and many helpful methods to use to operate database.
1. Insert one or multiple records to database
@ -58,10 +58,18 @@ There are 7 major ORM methods and many helpful methods to use to operate databas
3. Query multiple records from database
sliceOfStructs := new(Struct)
err := engine.Find(sliceOfStructs)
var sliceOfStructs []Struct
err := engine.Find(&sliceOfStructs)
// SELECT * FROM user
var mapOfStructs = make(map[int64]Struct)
err := engine.Find(&mapOfStructs)
// SELECT * FROM user
var int64s []int64
err := engine.Table("user").Cols("id").Find(&int64s)
// SELECT id FROM user
4. Query multiple records and record by record handle, there two methods, one is Iterate,
another is Rows
@ -91,20 +99,31 @@ another is Rows
counts, err := engine.Count(&user)
// SELECT count(*) AS total FROM user
8. Sum records
sumFloat64, err := engine.Sum(&user, "id")
// SELECT sum(id) from user
sumFloat64s, err := engine.Sums(&user, "id1", "id2")
// SELECT sum(id1), sum(id2) from user
sumInt64s, err := engine.SumsInt(&user, "id1", "id2")
// SELECT sum(id1), sum(id2) from user
Conditions
The above 7 methods could use with condition methods chainable.
Attention: the above 7 methods should be the last chainable method.
The above 8 methods could use with condition methods chainable.
Attention: the above 8 methods should be the last chainable method.
1. Id, In
1. ID, In
engine.Id(1).Get(&user) // for single primary key
engine.ID(1).Get(&user) // for single primary key
// SELECT * FROM user WHERE id = 1
engine.Id(core.PK{1, 2}).Get(&user) // for composite primary keys
engine.ID(core.PK{1, 2}).Get(&user) // for composite primary keys
// SELECT * FROM user WHERE id1 = 1 AND id2 = 2
engine.In("id", 1, 2, 3).Find(&users)
// SELECT * FROM user WHERE id IN (1, 2, 3)
engine.In("id", []int{1, 2, 3})
engine.In("id", []int{1, 2, 3}).Find(&users)
// SELECT * FROM user WHERE id IN (1, 2, 3)
2. Where, And, Or
@ -127,10 +146,10 @@ Attention: the above 7 methods should be the last chainable method.
// SELECT TOP 5 * FROM user // for mssql
// SELECT * FROM user LIMIT .. OFFSET 0 //for other databases
5. Sql, let you custom SQL
5. SQL, let you custom SQL
var users []User
engine.Sql("select * from user").Find(&users)
engine.SQL("select * from user").Find(&users)
6. Cols, Omit, Distinct