forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.go
More file actions
226 lines (179 loc) · 5.66 KB
/
database.go
File metadata and controls
226 lines (179 loc) · 5.66 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package database
import (
"context"
"database/sql"
"github.com/sourcegraph/log"
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
"github.com/sourcegraph/sourcegraph/internal/database/dbutil"
"github.com/sourcegraph/sourcegraph/internal/encryption"
)
// DB is an interface that embeds dbutil.DB, adding methods to
// return specialized stores on top of that interface. In time,
// the expectation is to replace uses of dbutil.DB with database.DB,
// and remove dbutil.DB altogether.
type DB interface {
dbutil.DB
basestore.ShareableStore
AccessTokens() AccessTokenStore
Authz() AuthzStore
BitbucketProjectPermissions() BitbucketProjectPermissionsStore
Conf() ConfStore
EventLogs() EventLogStore
SecurityEventLogs() SecurityEventLogsStore
ExternalServices() ExternalServiceStore
FeatureFlags() FeatureFlagStore
GitserverRepos() GitserverRepoStore
GitserverLocalClone() GitserverLocalCloneStore
GlobalState() GlobalStateStore
Namespaces() NamespaceStore
OrgInvitations() OrgInvitationStore
OrgMembers() OrgMemberStore
Orgs() OrgStore
OrgStats() OrgStatsStore
Phabricator() PhabricatorStore
Repos() RepoStore
RepoKVPs() RepoKVPStore
SavedSearches() SavedSearchStore
SearchContexts() SearchContextsStore
Settings() SettingsStore
SubRepoPerms() SubRepoPermsStore
TemporarySettings() TemporarySettingsStore
UserCredentials(encryption.Key) UserCredentialsStore
UserEmails() UserEmailsStore
UserExternalAccounts() UserExternalAccountsStore
UserPublicRepos() UserPublicRepoStore
Users() UserStore
WebhookLogs(encryption.Key) WebhookLogStore
Webhooks(encryption.Key) WebhookStore
RepoStatistics() RepoStatisticsStore
Transact(context.Context) (DB, error)
Done(error) error
}
var _ DB = (*db)(nil)
// NewDB creates a new DB from a dbutil.DB, providing a thin wrapper
// that has constructor methods for the more specialized stores.
func NewDB(logger log.Logger, inner *sql.DB) DB {
return &db{logger: logger, Store: basestore.NewWithHandle(basestore.NewHandleWithDB(inner, sql.TxOptions{}))}
}
func NewDBWith(logger log.Logger, other basestore.ShareableStore) DB {
return &db{logger: logger, Store: basestore.NewWithHandle(other.Handle())}
}
type db struct {
*basestore.Store
logger log.Logger
}
func (d *db) QueryContext(ctx context.Context, q string, args ...any) (*sql.Rows, error) {
return d.Handle().QueryContext(ctx, q, args...)
}
func (d *db) ExecContext(ctx context.Context, q string, args ...any) (sql.Result, error) {
return d.Handle().ExecContext(ctx, q, args...)
}
func (d *db) QueryRowContext(ctx context.Context, q string, args ...any) *sql.Row {
return d.Handle().QueryRowContext(ctx, q, args...)
}
func (d *db) Transact(ctx context.Context) (DB, error) {
tx, err := d.Store.Transact(ctx)
if err != nil {
return nil, err
}
return &db{logger: d.logger, Store: tx}, nil
}
func (d *db) Done(err error) error {
return d.Store.Done(err)
}
func (d *db) AccessTokens() AccessTokenStore {
return AccessTokensWith(d.Store)
}
func (d *db) BitbucketProjectPermissions() BitbucketProjectPermissionsStore {
return BitbucketProjectPermissionsStoreWith(d.Store)
}
func (d *db) Authz() AuthzStore {
return AuthzWith(d.Store)
}
func (d *db) Conf() ConfStore {
return &confStore{Store: basestore.NewWithHandle(d.Handle())}
}
func (d *db) EventLogs() EventLogStore {
return EventLogsWith(d.Store)
}
func (d *db) SecurityEventLogs() SecurityEventLogsStore {
return SecurityEventLogsWith(d.logger, d.Store)
}
func (d *db) ExternalServices() ExternalServiceStore {
return ExternalServicesWith(d.logger, d.Store)
}
func (d *db) FeatureFlags() FeatureFlagStore {
return FeatureFlagsWith(d.Store)
}
func (d *db) GitserverRepos() GitserverRepoStore {
return GitserverReposWith(d.Store)
}
func (d *db) GitserverLocalClone() GitserverLocalCloneStore {
return GitserverLocalCloneStoreWith(d.Store)
}
func (d *db) GlobalState() GlobalStateStore {
return GlobalStateWith(d.Store)
}
func (d *db) Namespaces() NamespaceStore {
return NamespacesWith(d.Store)
}
func (d *db) OrgInvitations() OrgInvitationStore {
return OrgInvitationsWith(d.Store)
}
func (d *db) OrgMembers() OrgMemberStore {
return OrgMembersWith(d.Store)
}
func (d *db) Orgs() OrgStore {
return OrgsWith(d.Store)
}
func (d *db) OrgStats() OrgStatsStore {
return OrgStatsWith(d.Store)
}
func (d *db) Phabricator() PhabricatorStore {
return PhabricatorWith(d.Store)
}
func (d *db) Repos() RepoStore {
return ReposWith(d.logger, d.Store)
}
func (d *db) RepoKVPs() RepoKVPStore {
return &repoKVPStore{d.Store}
}
func (d *db) SavedSearches() SavedSearchStore {
return SavedSearchesWith(d.Store)
}
func (d *db) SearchContexts() SearchContextsStore {
return SearchContextsWith(d.logger, d.Store)
}
func (d *db) Settings() SettingsStore {
return SettingsWith(d.Store)
}
func (d *db) SubRepoPerms() SubRepoPermsStore {
return SubRepoPermsWith(d.Store)
}
func (d *db) TemporarySettings() TemporarySettingsStore {
return TemporarySettingsWith(d.Store)
}
func (d *db) UserCredentials(key encryption.Key) UserCredentialsStore {
return UserCredentialsWith(d.logger, d.Store, key)
}
func (d *db) UserEmails() UserEmailsStore {
return UserEmailsWith(d.Store)
}
func (d *db) UserExternalAccounts() UserExternalAccountsStore {
return ExternalAccountsWith(d.logger, d.Store)
}
func (d *db) UserPublicRepos() UserPublicRepoStore {
return UserPublicReposWith(d.Store)
}
func (d *db) Users() UserStore {
return UsersWith(d.logger, d.Store)
}
func (d *db) WebhookLogs(key encryption.Key) WebhookLogStore {
return WebhookLogsWith(d.Store, key)
}
func (d *db) Webhooks(key encryption.Key) WebhookStore {
return WebhooksWith(d.Store, key)
}
func (d *db) RepoStatistics() RepoStatisticsStore {
return RepoStatisticsWith(d.Store)
}