forked from textileio/go-textile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastore.go
202 lines (178 loc) · 4.83 KB
/
datastore.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package repo
import (
"database/sql"
"strings"
"time"
"github.com/textileio/textile-go/keypair"
)
type Datastore interface {
Config() ConfigStore
Profile() ProfileStore
Contacts() ContactStore
Files() FileStore
Threads() ThreadStore
ThreadInvites() ThreadInviteStore
ThreadPeers() ThreadPeerStore
ThreadMessages() ThreadMessageStore
Blocks() BlockStore
Notifications() NotificationStore
CafeSessions() CafeSessionStore
CafeRequests() CafeRequestStore
CafeMessages() CafeMessageStore
CafeClientNonces() CafeClientNonceStore
CafeClients() CafeClientStore
CafeClientThreads() CafeClientThreadStore
CafeClientMessages() CafeClientMessageStore
Ping() error
Close()
}
type Queryable interface {
BeginTransaction() (*sql.Tx, error)
PrepareQuery(string) (*sql.Stmt, error)
PrepareAndExecuteQuery(string, ...interface{}) (*sql.Rows, error)
ExecuteQuery(string, ...interface{}) (sql.Result, error)
}
type ConfigStore interface {
Init(pin string) error
Configure(accnt *keypair.Full, created time.Time) error
GetAccount() (*keypair.Full, error)
GetCreationDate() (time.Time, error)
IsEncrypted() bool
}
type ProfileStore interface {
SetUsername(username string) error
GetUsername() (*string, error)
SetAvatar(uri string) error
GetAvatar() (*string, error)
}
type ContactStore interface {
Queryable
Add(contact *Contact) error
AddOrUpdate(contact *Contact) error
Get(id string) *Contact
List() []Contact
ListByAddress(address string) []Contact
Count() int
Delete(id string) error
}
type FileStore interface {
Queryable
Add(file *File) error
Get(hash string) *File
GetByPrimary(mill string, checksum string) *File
GetBySource(mill string, source string, opts string) *File
AddTarget(hash string, target string) error
RemoveTarget(hash string, target string) error
Count() int
Delete(hash string) error
}
type ThreadStore interface {
Queryable
Add(thread *Thread) error
Get(id string) *Thread
GetByKey(key string) *Thread
List() []Thread
Count() int
UpdateHead(id string, head string) error
Delete(id string) error
}
type ThreadInviteStore interface {
Queryable
Add(invite *ThreadInvite) error
Get(id string) *ThreadInvite
List() []ThreadInvite
Delete(id string) error
}
type ThreadPeerStore interface {
Queryable
Add(peer *ThreadPeer) error
List() []ThreadPeer
ListById(id string) []ThreadPeer
ListByThread(threadId string) []ThreadPeer
ListUnwelcomedByThread(threadId string) []ThreadPeer
WelcomeByThread(thread string) error
Count(distinct bool) int
Delete(id string, thread string) error
DeleteById(id string) error
DeleteByThread(thread string) error
}
type ThreadMessageStore interface {
Queryable
Add(msg *ThreadMessage) error
List(offset string, limit int) []ThreadMessage
Delete(id string) error
}
type BlockStore interface {
Queryable
Add(block *Block) error
Get(id string) *Block
List(offset string, limit int, query string) []Block
Count(query string) int
Delete(id string) error
DeleteByThread(threadId string) error
}
type NotificationStore interface {
Queryable
Add(notification *Notification) error
Get(id string) *Notification
Read(id string) error
ReadAll() error
List(offset string, limit int) []Notification
CountUnread() int
Delete(id string) error
DeleteByActor(actorId string) error
DeleteBySubject(subjectId string) error
DeleteByBlock(blockId string) error
}
// Cafe user-side stores
type CafeSessionStore interface {
AddOrUpdate(session *CafeSession) error
Get(cafeId string) *CafeSession
List() []CafeSession
Delete(cafeId string) error
}
type CafeRequestStore interface {
Queryable
Add(req *CafeRequest) error
List(offset string, limit int) []CafeRequest
Delete(id string) error
DeleteByCafe(cafeId string) error
}
type CafeMessageStore interface {
Queryable
Add(msg *CafeMessage) error
List(offset string, limit int) []CafeMessage
AddAttempt(id string) error
Delete(id string) error
}
// Cafe host-side stores
type CafeClientNonceStore interface {
Add(nonce *CafeClientNonce) error
Get(value string) *CafeClientNonce
Delete(value string) error
}
type CafeClientStore interface {
Add(account *CafeClient) error
Get(id string) *CafeClient
Count() int
List() []CafeClient
ListByAddress(address string) []CafeClient
UpdateLastSeen(id string, date time.Time) error
Delete(id string) error
}
type CafeClientThreadStore interface {
AddOrUpdate(thrd *CafeClientThread) error
ListByClient(clientId string) []CafeClientThread
Delete(id string, clientId string) error
DeleteByClient(clientId string) error
}
type CafeClientMessageStore interface {
AddOrUpdate(message *CafeClientMessage) error
ListByClient(clientId string, limit int) []CafeClientMessage
CountByClient(clientId string) int
Delete(id string, clientId string) error
DeleteByClient(clientId string, limit int) error
}
func ConflictError(err error) bool {
return strings.Contains(err.Error(), "UNIQUE constraint failed")
}