-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite_models.go
More file actions
85 lines (72 loc) · 2.1 KB
/
sqlite_models.go
File metadata and controls
85 lines (72 loc) · 2.1 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
package main
import (
"time"
)
// SQLite models from sqlite branch
type SqliteModel struct {
ID int `gorm:"primaryKey" json:"-"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
type SqliteBook struct {
SqliteModel
UUID string `json:"uuid" gorm:"uniqueIndex;type:text"`
UserID int `json:"user_id" gorm:"index"`
Label string `json:"label" gorm:"index"`
Notes []SqliteNote `json:"notes" gorm:"foreignKey:BookUUID;references:UUID"`
AddedOn int64 `json:"added_on"`
EditedOn int64 `json:"edited_on"`
USN int `json:"-" gorm:"index"`
Deleted bool `json:"-" gorm:"default:false"`
}
func (SqliteBook) TableName() string {
return "books"
}
type SqliteNote struct {
SqliteModel
UUID string `json:"uuid" gorm:"index;type:text"`
UserID int `json:"user_id" gorm:"index"`
BookUUID string `json:"book_uuid" gorm:"index;type:text"`
Body string `json:"content"`
AddedOn int64 `json:"added_on"`
EditedOn int64 `json:"edited_on"`
Public bool `json:"public" gorm:"default:false"`
USN int `json:"-" gorm:"index"`
Deleted bool `json:"-" gorm:"default:false"`
Client string `gorm:"index"`
}
func (SqliteNote) TableName() string {
return "notes"
}
type SqliteUser struct {
SqliteModel
UUID string `json:"uuid" gorm:"type:text;index"`
Email NullString `gorm:"index"`
Password NullString `json:"-"`
LastLoginAt *time.Time `json:"-"`
MaxUSN int `json:"-" gorm:"default:0"`
FullSyncBefore int64 `json:"-" gorm:"default:0"`
}
func (SqliteUser) TableName() string {
return "users"
}
type SqliteToken struct {
SqliteModel
UserID int `gorm:"index"`
Value string `gorm:"index"`
Type string
UsedAt *time.Time
}
func (SqliteToken) TableName() string {
return "tokens"
}
type SqliteSession struct {
SqliteModel
UserID int `gorm:"index"`
Key string `gorm:"index"`
LastUsedAt time.Time
ExpiresAt time.Time
}
func (SqliteSession) TableName() string {
return "sessions"
}