This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
forked from gocassa/gocassa
-
Notifications
You must be signed in to change notification settings - Fork 13
/
multimap_table.go
69 lines (60 loc) · 1.95 KB
/
multimap_table.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
62
63
64
65
66
67
68
69
package gocassa
type multimapT struct {
t Table
fieldToIndexBy string
idField string
}
func (mm *multimapT) Table() Table { return mm.t }
func (mm *multimapT) Create() error { return mm.Table().Create() }
func (mm *multimapT) CreateIfNotExist() error { return mm.Table().CreateIfNotExist() }
func (mm *multimapT) Name() string { return mm.Table().Name() }
func (mm *multimapT) Recreate() error { return mm.Table().Recreate() }
func (mm *multimapT) CreateStatement() (Statement, error) { return mm.Table().CreateStatement() }
func (mm *multimapT) CreateIfNotExistStatement() (Statement, error) {
return mm.Table().CreateIfNotExistStatement()
}
func (mm *multimapT) Update(field, id interface{}, m map[string]interface{}) Op {
return mm.Table().
Where(Eq(mm.fieldToIndexBy, field),
Eq(mm.idField, id)).
Update(m)
}
func (mm *multimapT) Set(v interface{}) Op {
return mm.Table().
Set(v)
}
func (mm *multimapT) Delete(field, id interface{}) Op {
return mm.Table().
Where(Eq(mm.fieldToIndexBy, field), Eq(mm.idField, id)).
Delete()
}
func (mm *multimapT) DeleteAll(field interface{}) Op {
return mm.Table().
Where(Eq(mm.fieldToIndexBy, field)).
Delete()
}
func (mm *multimapT) Read(field, id, pointer interface{}) Op {
return mm.Table().
Where(Eq(mm.fieldToIndexBy, field),
Eq(mm.idField, id)).
ReadOne(pointer)
}
func (mm *multimapT) List(field, startId interface{}, limit int, pointerToASlice interface{}) Op {
rels := []Relation{Eq(mm.fieldToIndexBy, field)}
if startId != nil {
rels = append(rels, GTE(mm.idField, startId))
}
return mm.Table().
WithOptions(Options{
Limit: limit,
}).
Where(rels...).
Read(pointerToASlice)
}
func (mm *multimapT) WithOptions(o Options) MultimapTable {
return &multimapT{
t: mm.Table().WithOptions(o),
fieldToIndexBy: mm.fieldToIndexBy,
idField: mm.idField,
}
}