-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.go
61 lines (54 loc) · 1.5 KB
/
db.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package tableorm
import (
"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore"
"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore/search"
"github.com/diemus/tableorm/query"
)
func NewDB(endPoint, instanceName, accessKeyId, accessKeySecret string, options ...tablestore.ClientOption) *DB {
client := tablestore.NewClient(endPoint, instanceName, accessKeyId, accessKeySecret, options...)
return &DB{
client: client,
//没传入query时使用MatchAllQuery
query: query.MatchAllQuery(),
offset: -1,
limit: -1,
getTotalCount: false,
}
}
type DB struct {
client *tablestore.TableStoreClient
query search.Query
offset int
limit int
getTotalCount bool
sorters []search.Sorter
token []byte
//Collapse *Collapse
}
func (db *DB) Query(queries ...search.Query) *DB {
if len(queries) > 1 {
db.query = query.And(queries...)
} else if len(queries) == 1 {
db.query = queries[0]
} else {
//没传入query时使用MatchAllQuery
db.query = query.MatchAllQuery()
}
return db
}
//当需要获取的总条数小于2000行时,可以通过limit和offset进行翻页,limit+offset <= 2000。
func (db *DB) Offset(n int) *DB {
db.offset = n
return db
}
//当需要获取的总条数小于2000行时,可以通过limit和offset进行翻页,limit+offset <= 2000。
func (db *DB) Limit(n int) *DB {
db.limit = n
return db
}
func (db *DB) Token(token []byte) *DB {
db.offset = -1
db.limit = -1
db.token = token
return db
}