forked from zbyte/go-kallax
-
Notifications
You must be signed in to change notification settings - Fork 2
/
store.go
127 lines (105 loc) · 2.39 KB
/
store.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
package tests
import (
"time"
"github.com/networkteam/go-kallax"
)
type A struct {
kallax.Model `table:"a" pk:"id,autoincr"`
ID int64
Name string
B *B
}
func newA(name string) *A {
return &A{Name: name}
}
type B struct {
kallax.Model `table:"b" pk:"id,autoincr"`
ID int64
Name string
A *A `fk:",inverse"`
C *C
}
func newB(name string, a *A) *B {
b := &B{Name: name, A: a}
a.B = b
return b
}
type C struct {
kallax.Model `table:"c" pk:"id,autoincr"`
ID int64
Name string
B *B `fk:",inverse"`
}
func newC(name string, b *B) *C {
c := &C{Name: name, B: b}
b.C = c
return c
}
type AliasSliceString []string
type StoreFixture struct {
kallax.Model `table:"store" pk:"id"`
ID kallax.ULID
Foo string
SliceProp []string
AliasSliceProp AliasSliceString
}
func newStoreFixture() *StoreFixture {
return &StoreFixture{ID: kallax.NewULID()}
}
type StoreWithConstructFixture struct {
kallax.Model `table:"store_construct"`
ID kallax.ULID `pk:""`
Foo string
}
func newStoreWithConstructFixture(f string) *StoreWithConstructFixture {
if f == "" {
return nil
}
return &StoreWithConstructFixture{ID: kallax.NewULID(), Foo: f}
}
type StoreWithNewFixture struct {
kallax.Model `table:"store_new"`
ID kallax.ULID `pk:""`
Foo string
Bar string
}
func newStoreWithNewFixture() *StoreWithNewFixture {
return &StoreWithNewFixture{ID: kallax.NewULID()}
}
type MultiKeySortFixture struct {
kallax.Model `table:"query"`
ID kallax.ULID `pk:""`
Name string
Start time.Time
End time.Time
}
func newMultiKeySortFixture() *MultiKeySortFixture {
return &MultiKeySortFixture{ID: kallax.NewULID()}
}
type SomeJSON struct {
Foo int
}
type Nullable struct {
kallax.Model `table:"nullable"`
ID int64 `pk:"autoincr"`
T *time.Time
SomeJSON *SomeJSON
Scanner *kallax.ULID
}
type Parent struct {
kallax.Model `table:"parents" pk:"id,autoincr"`
ID int64
Name string
Children []*Child
}
type Child struct {
kallax.Model `table:"children"`
ID int64 `pk:"autoincr"`
Name string
}
type ParentNoPtr struct {
kallax.Model `table:"parents"`
ID int64 `pk:"autoincr"`
Name string
Children []Child `fk:"parent_id"`
}