/
advanced.go
44 lines (35 loc) · 1.04 KB
/
advanced.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package db
// Limit adds a limit to the query
func (b *DB) Limit(limit interface{}) *DB {
return b.clone(b.DB.Limit(limit))
}
// Skip adds an offset to the query
func (b *DB) Skip(skip interface{}) *DB {
return b.clone(b.Offset(skip))
}
// Count 's the database records in the given table
func (b *DB) Count() interface{} {
var count interface{}
b.DB.Count(&count)
return count
}
// Table specify the table you would like to run db operations
func (b *DB) Table(name string) *DB {
return b.clone(b.DB.Table(name))
}
// Select specifies field you want to query from the database
func (b *DB) Select(query interface{}, args ...interface{}) *DB {
return b.clone(b.DB.Select(query, args...))
}
// Group specify the group method on the find
func (b *DB) Group(query string) *DB {
return b.clone(b.DB.Group(query))
}
// Having specify HAVING conditions for GROUP BY
func (b *DB) Having(query string) *DB {
return b.clone(b.DB.Having(query))
}
// Scan scan value to a struct
func (b *DB) Scan(dest interface{}) *DB {
return b.clone(b.DB.Scan(dest))
}