forked from mercari/datastore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.go
119 lines (95 loc) · 3 KB
/
interfaces.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package datastore
import (
"context"
)
var FromContext ClientGenerator
type ClientGenerator func(ctx context.Context, opts ...ClientOption) (Client, error)
type Client interface {
Get(ctx context.Context, key Key, dst interface{}) error
GetMulti(ctx context.Context, keys []Key, dst interface{}) error
Put(ctx context.Context, key Key, src interface{}) (Key, error)
PutMulti(ctx context.Context, keys []Key, src interface{}) ([]Key, error)
Delete(ctx context.Context, key Key) error
DeleteMulti(ctx context.Context, keys []Key) error
NewTransaction(ctx context.Context) (Transaction, error)
RunInTransaction(ctx context.Context, f func(tx Transaction) error) (Commit, error)
Run(ctx context.Context, q Query) Iterator
AllocatedIDs(ctx context.Context, keys []Key) ([]Key, error)
Count(ctx context.Context, q Query) (int, error)
GetAll(ctx context.Context, q Query, dst interface{}) ([]Key, error)
IncompleteKey(kind string, parent Key) Key
NameKey(kind, name string, parent Key) Key
IDKey(kind string, id int64, parent Key) Key
NewQuery(kind string) Query
Close() error
DecodeKey(encoded string) (Key, error)
DecodeCursor(s string) (Cursor, error)
Batch() *Batch
AppendCacheStrategy(strategy CacheStrategy) // NOTE First-In Last-Apply
RemoveCacheStrategy(strategy CacheStrategy) bool
SwapContext(ctx context.Context) context.Context
}
type Key interface {
Kind() string
ID() int64
Name() string
ParentKey() Key
Namespace() string
String() string
GobEncode() ([]byte, error)
GobDecode(buf []byte) error
MarshalJSON() ([]byte, error)
UnmarshalJSON(buf []byte) error
Encode() string
Equal(o Key) bool
Incomplete() bool
}
type PendingKey interface {
StoredContext() context.Context
}
type Transaction interface {
Get(key Key, dst interface{}) error
GetMulti(keys []Key, dst interface{}) error
Put(key Key, src interface{}) (PendingKey, error)
PutMulti(keys []Key, src interface{}) ([]PendingKey, error)
Delete(key Key) error
DeleteMulti(keys []Key) error
Commit() (Commit, error)
Rollback() error
Batch() *TransactionBatch
}
type Commit interface {
Key(p PendingKey) Key
}
type GeoPoint struct {
Lat, Lng float64
}
type Query interface {
Ancestor(ancestor Key) Query
EventualConsistency() Query
Namespace(ns string) Query
Transaction(t Transaction) Query
Filter(filterStr string, value interface{}) Query
Order(fieldName string) Query
Project(fieldNames ...string) Query
Distinct() Query
// NOT IMPLEMENTED ON APPENGINE DistinctOn(fieldNames ...string) *Query
KeysOnly() Query
Limit(limit int) Query
Offset(offset int) Query
Start(c Cursor) Query
End(c Cursor) Query
Dump() *QueryDump
}
type Iterator interface {
Next(dst interface{}) (Key, error)
Cursor() (Cursor, error)
}
type Cursor interface {
String() string
}
type PropertyTranslator interface {
ToPropertyValue(ctx context.Context) (interface{}, error)
FromPropertyValue(ctx context.Context, p Property) (dst interface{}, err error)
}
// TODO ComplexPropertyTranslator e.g. ToProperties(ctx context.Context) ([]Property, error)