forked from samonzeweb/godb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixtures.go
115 lines (95 loc) · 2.43 KB
/
fixtures.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
package common
import (
"database/sql"
"time"
)
type Book struct {
Id int `db:"id,key,auto"`
Title string `db:"title"`
Author string `db:"author"`
Published time.Time `db:"published"`
Version int `db:"version,oplock"`
}
func (*Book) TableName() string {
return "books"
}
type Inventory struct {
Id int `db:"id,key,auto"`
BookId int `db:"book_id"`
LastInventory time.Time `db:"last_inventory"`
Counting int `db:"counting"`
}
func (*Inventory) TableName() string {
return "inventories"
}
type InventoryPart struct {
Id sql.NullInt64 `db:"id"`
Counting sql.NullInt64 `db:"counting"`
}
type BooksWithInventories struct {
Book `db:",rel=books"`
InventoryPart `db:",rel=inventories"`
}
type CountByAuthor struct {
Author string `db:"author"`
Count int `db:"count"`
}
var authorTolkien = "J.R.R. tolkien"
var bookTheHobbit = Book{
Title: "The Hobbit",
Author: authorTolkien,
Published: time.Date(1937, 9, 21, 0, 0, 0, 0, time.UTC),
}
var bookTheFellowshipOfTheRing = Book{
Title: "The Fellowship of the Ring",
Author: authorTolkien,
Published: time.Date(1954, 7, 29, 0, 0, 0, 0, time.UTC),
}
var bookTheTwoTowers = Book{
Title: "The Two Towers",
Author: authorTolkien,
Published: time.Date(1954, 11, 11, 0, 0, 0, 0, time.UTC),
}
var bookTheReturnOfTheKing = Book{
Title: "The Return of the King",
Author: authorTolkien,
Published: time.Date(1955, 10, 20, 0, 0, 0, 0, time.UTC),
}
var setTheLordOfTheRing = []Book{
bookTheFellowshipOfTheRing,
bookTheTwoTowers,
bookTheReturnOfTheKing,
}
var authorAssimov = "Isaac Assimov"
var bookFoundation = Book{
Title: "Foundation",
Author: authorAssimov,
// Don't know the exact date
Published: time.Date(1951, 1, 1, 0, 0, 0, 0, time.UTC),
}
var bookFoundationAndEmpire = Book{
Title: "Foundation and Empire",
Author: authorAssimov,
// Don't know the exact date
Published: time.Date(1952, 1, 1, 0, 0, 0, 0, time.UTC),
}
var bookSecondFoundation = Book{
Title: "Second Foundation",
Author: authorAssimov,
// Don't know the exact date
Published: time.Date(1953, 1, 1, 0, 0, 0, 0, time.UTC),
}
var setFoundation = []Book{
bookFoundation,
bookFoundationAndEmpire,
bookSecondFoundation,
}
var setAllBooks = []Book{
bookTheHobbit,
bookTheFellowshipOfTheRing,
bookTheTwoTowers,
bookTheReturnOfTheKing,
bookFoundation,
bookFoundationAndEmpire,
bookSecondFoundation,
}