-
Notifications
You must be signed in to change notification settings - Fork 38
/
types.go
491 lines (419 loc) 路 12.8 KB
/
types.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
package common
import (
"time"
)
// AccessType is whether a database is private, or public, or both
type AccessType int
const (
DB_BOTH AccessType = iota
DB_PRIVATE
DB_PUBLIC
)
type ActivityRange string
const (
TODAY ActivityRange = "today"
THIS_WEEK = "week"
THIS_MONTH = "month"
ALL_TIME = "all"
)
type ForkType int
const (
SPACE ForkType = iota
ROOT
STEM
BRANCH
END
)
// ValType indicates the type of data in a field returned from a SQLite query
type ValType int
const (
Binary ValType = iota
Image
Null
Text
Integer
Float
)
// DefaultNumDisplayRows is the number of rows to display by default on the database page
const DefaultNumDisplayRows = 25
// MaxDatabaseSize is the maximum database size accepted for upload (in MB)
const MaxDatabaseSize = 512
// MaxLicenceSize is the maximum licence size accepted for upload (in MB)
const MaxLicenceSize = 1
// MinioFolderChars is the number of leading characters of a files' sha256 used as the Minio folder name
// eg: When set to 6, then "34f4255a737156147fbd0a44323a895d18ade79d4db521564d1b0dbb8764cbbc"
//
// -> Minio folder: "34f425"
// -> Minio filename: "5a737156147fbd0a44323a895d18ade79d4db521564d1b0dbb8764cbbc"
const MinioFolderChars = 6
// QuerySource is used internally to help choose the output format from a SQL query
type QuerySource int
const (
QuerySourceDB4S QuerySource = iota
QuerySourceVisualisation
QuerySourceAPI
QuerySourceInternal
)
// SetAccessType is used for setting the public flag of a database
type SetAccessType int
const (
SetToPublic SetAccessType = iota
SetToPrivate
KeepCurrentAccessType
)
// SetDBType is used for setting what type of database we're working with
type SetDBType int
const (
DBTypeStandard SetDBType = iota
DBTypeLive
)
type ActivityRow struct {
Count int `json:"count"`
DBName string `json:"dbname"`
Owner string `json:"owner"`
}
type ActivityStats struct {
Downloads []ActivityRow
Forked []ActivityRow
Starred []ActivityRow
Uploads []UploadRow
Viewed []ActivityRow
}
// APIJSONColumn is a copy of the Column type from github.com/gwenn/gosqlite, but including JSON field name info
type APIJSONColumn struct {
Cid int `json:"column_id"`
Name string `json:"name"`
DataType string `json:"data_type"`
NotNull bool `json:"not_null"`
DfltValue string `json:"default_value"`
Pk int `json:"primary_key"`
}
// APIJSONIndexColumn holds the details of one column of a SQLite database index. It's used by our API for returning
// index information
type APIJSONIndexColumn struct {
CID int `json:"id"`
Name string `json:"name"`
}
// APIJSONIndex holds the details of an index for a SQLite database. It's used by our API for returning index information
type APIJSONIndex struct {
Name string `json:"name"`
Table string `json:"table"`
Columns []APIJSONIndexColumn `json:"columns"`
}
// APIKey is an internal structure used for passing around user API keys
type APIKey struct {
Uuid string `json:"uuid"`
Key string `json:"key"`
DateCreated time.Time `json:"date_created"`
ExpiryDate *time.Time `json:"expiry_date"`
Comment string `json:"comment"`
}
type BranchEntry struct {
Commit string `json:"commit"`
CommitCount int `json:"commit_count"`
Description string `json:"description"`
}
type CommitData struct {
AuthorAvatar string `json:"author_avatar"`
AuthorEmail string `json:"author_email"`
AuthorName string `json:"author_name"`
AuthorUsername string `json:"author_username"`
ID string `json:"id"`
Parent string `json:"parent"`
LicenceChange string `json:"licence_change"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
}
type CommitEntry struct {
AuthorEmail string `json:"author_email"`
AuthorName string `json:"author_name"`
CommitterEmail string `json:"committer_email"`
CommitterName string `json:"committer_name"`
ID string `json:"id"`
Message string `json:"message"`
OtherParents []string `json:"other_parents"`
Parent string `json:"parent"`
Timestamp time.Time `json:"timestamp"`
Tree DBTree `json:"tree"`
}
type DatabaseName struct {
Database string
Owner string
}
type DataValue struct {
Name string
Type ValType
Value interface{}
}
type DataRow []DataValue
type DBEntry struct {
DateEntry time.Time
DBName string
Owner string
OwnerDisplayName string `json:"display_name"`
}
type DBTreeEntryType string
const (
TREE DBTreeEntryType = "tree"
DATABASE = "db"
LICENCE = "licence"
)
type DBTree struct {
ID string `json:"id"`
Entries []DBTreeEntry `json:"entries"`
}
type DBTreeEntry struct {
EntryType DBTreeEntryType `json:"entry_type"`
LastModified time.Time `json:"last_modified"`
LicenceSHA string `json:"licence"`
Name string `json:"name"`
Sha256 string `json:"sha256"`
Size int64 `json:"size"`
}
type DBInfo struct {
Branch string
Branches int
BranchList []string
Commits int
CommitID string
Contributors int
Database string
DateCreated time.Time
DBEntry DBTreeEntry
DefaultBranch string
DefaultTable string
Discussions int
Downloads int
ForkDatabase string
ForkDeleted bool
ForkOwner string
Forks int
FullDesc string
IsLive bool
LastModified time.Time
Licence string
LicenceURL string
LiveNode string
MRs int
MyStar bool
MyWatch bool
OneLineDesc string
Owner string
Public bool
RepoModified time.Time
Releases int
SHA256 string
Size int64
SourceURL string
Stars int
Tables []string
Tags int
Views int
Watchers int
}
type DiscussionCommentType string
const (
TEXT DiscussionCommentType = "txt"
CLOSE = "cls"
REOPEN = "rop"
)
type DiscussionCommentEntry struct {
AvatarURL string `json:"avatar_url"`
Body string `json:"body"`
BodyRendered string `json:"body_rendered"`
Commenter string `json:"commenter"`
DateCreated time.Time `json:"creation_date"`
EntryType DiscussionCommentType `json:"entry_type"`
ID int `json:"com_id"`
}
type DiscussionType int
const (
DISCUSSION DiscussionType = 0 // These are not iota, as it would be seriously bad for these numbers to change
MERGE_REQUEST = 1
)
type DiscussionEntry struct {
AvatarURL string `json:"avatar_url"`
Body string `json:"body"`
BodyRendered string `json:"body_rendered"`
CommentCount int `json:"comment_count"`
Creator string `json:"creator"`
DateCreated time.Time `json:"creation_date"`
ID int `json:"disc_id"`
LastModified time.Time `json:"last_modified"`
MRDetails MergeRequestEntry `json:"mr_details"`
Open bool `json:"open"`
Title string `json:"title"`
Type DiscussionType `json:"discussion_type"`
}
type EventDetails struct {
DBName string `json:"database_name"`
DiscID int `json:"discussion_id"`
ID string `json:"event_id"`
Message string `json:"message"`
Owner string `json:"database_owner"`
Timestamp time.Time `json:"event_timestamp"`
Title string `json:"title"`
Type EventType `json:"event_type"`
URL string `json:"event_url"`
UserName string `json:"username"`
}
type EventType int
const (
EVENT_NEW_DISCUSSION EventType = 0 // These are not iota, as it would be seriously bad for these numbers to change
EVENT_NEW_MERGE_REQUEST = 1
EVENT_NEW_COMMENT = 2
EVENT_NEW_RELEASE = 3
)
type ForkEntry struct {
DBName string `json:"database_name"`
ForkedFrom int `json:"forked_from"`
IconList []ForkType `json:"icon_list"`
ID int `json:"id"`
Owner string `json:"database_owner"`
Processed bool `json:"processed"`
Public bool `json:"public"`
Deleted bool `json:"deleted"`
}
// JsonError holds the details of an error. It's used by our API for returning error information
type JsonError struct {
Error string `json:"error"`
}
type LicenceEntry struct {
FileFormat string `json:"file_format"`
FullName string `json:"full_name"`
Order int `json:"order"`
Sha256 string `json:"sha256"`
URL string `json:"url"`
}
type MergeRequestState int
const (
OPEN MergeRequestState = 0 // These are not iota, as it would be seriously bad for these numbers to change
CLOSED_WITH_MERGE = 1
CLOSED_WITHOUT_MERGE = 2
)
type MergeRequestEntry struct {
Commits []CommitEntry `json:"commits"`
DestBranch string `json:"destination_branch"`
SourceBranch string `json:"source_branch"`
SourceDBID int64 `json:"source_database_id"`
SourceDBName string `json:"source_database_name"`
SourceOwner string `json:"source_owner"`
State MergeRequestState `json:"state"`
}
type ReleaseEntry struct {
Commit string `json:"commit"`
Date time.Time `json:"date"`
Description string `json:"description"`
ReleaserEmail string `json:"email"`
ReleaserName string `json:"name"`
Size int64 `json:"size"`
}
type ShareDatabasePermissions string
const (
MayRead ShareDatabasePermissions = "r"
MayReadAndWrite ShareDatabasePermissions = "rw"
)
// ShareDatabasePermissionsOthers contains a list of user permissions for a given database
type ShareDatabasePermissionsOthers struct {
DBName string `json:"database_name"`
IsLive bool `json:"is_live"`
Perms map[string]ShareDatabasePermissions `json:"user_permissions"`
}
// ShareDatabasePermissionsUser contains a list of shared database permissions for a given user
type ShareDatabasePermissionsUser struct {
OwnerName string `json:"owner_name"`
DBName string `json:"database_name"`
IsLive bool `json:"is_live"`
Permission ShareDatabasePermissions `json:"permission"`
}
type SqlHistoryItemStates string
const (
Executed SqlHistoryItemStates = "executed"
Queried SqlHistoryItemStates = "queried"
Error SqlHistoryItemStates = "error"
)
type SqlHistoryItem struct {
Statement string `json:"input"`
Result interface{} `json:"output"`
State SqlHistoryItemStates `json:"state"`
}
type SQLiteDBinfo struct {
Info DBInfo
MaxRows int
MinioBkt string
MinioId string
}
type SQLiteRecordSet struct {
ColCount int
ColNames []string
Offset int
PrimaryKeyColumns []string `json:"primaryKeyColumns,omitempty"`
Records []DataRow
RowCount int
SortCol string
SortDir string
Tablename string
TotalRows int
}
type StatusUpdateEntry struct {
DiscID int `json:"discussion_id"`
Title string `json:"title"`
URL string `json:"event_url"`
}
type TagEntry struct {
Commit string `json:"commit"`
Date time.Time `json:"date"`
Description string `json:"description"`
TaggerEmail string `json:"email"`
TaggerName string `json:"name"`
}
type UploadRow struct {
DBName string `json:"dbname"`
Owner string `json:"owner"`
UploadDate time.Time `json:"upload_date"`
}
// UserInfoSlice is used for sorting a UserInfo list by Last Modified date descending
type UserInfoSlice []UserInfo
func (u UserInfoSlice) Len() int {
return len(u)
}
func (u UserInfoSlice) Less(i, j int) bool {
return u[i].LastModified.After(u[j].LastModified) // Swap to Before() for an ascending list
}
func (u UserInfoSlice) Swap(i, j int) {
u[i], u[j] = u[j], u[i]
}
type UserDetails struct {
AvatarURL string
ClientCert []byte
DateJoined time.Time
DisplayName string
Email string
MinioBucket string
Password string
PHash []byte
PVerify string
Username string
}
type UserInfo struct {
FullName string `json:"full_name"`
LastModified time.Time
Username string
}
type VisParamsV2 struct {
ChartType string `json:"chart_type"`
ShowXLabel bool `json:"show_x_label"`
ShowYLabel bool `json:"show_y_label"`
SQL string `json:"sql"`
XAXisColumn string `json:"x_axis_label"`
YAXisColumn string `json:"y_axis_label"`
}
type VisRowV1 struct {
Name string
Value int
}
type WhereClause struct {
Column string
Type string
Value string
}