@@ -25,11 +25,7 @@ func TestBooks(t *testing.T) {
25
25
dq := New (db )
26
26
27
27
// create an author
28
- result , err := dq .CreateAuthor (ctx , "Unknown Master" )
29
- if err != nil {
30
- t .Fatal (err )
31
- }
32
- authorID , err := result .LastInsertId ()
28
+ a , err := dq .CreateAuthor (ctx , "Unknown Master" )
33
29
if err != nil {
34
30
t .Fatal (err )
35
31
}
@@ -45,76 +41,69 @@ func TestBooks(t *testing.T) {
45
41
// save first book
46
42
now := time .Now ()
47
43
_ , err = tq .CreateBook (ctx , CreateBookParams {
48
- AuthorID : int64 ( authorID ) ,
44
+ AuthorID : a . AuthorID ,
49
45
Isbn : "1" ,
50
46
Title : "my book title" ,
51
47
BookType : BooksBookTypeFICTION ,
52
48
Yr : 2016 ,
53
49
Available : now ,
50
+ Tag : "" ,
54
51
})
55
52
if err != nil {
56
53
t .Fatal (err )
57
54
}
58
55
59
56
// save second book
60
- result , err = tq .CreateBook (ctx , CreateBookParams {
61
- AuthorID : int64 ( authorID ) ,
57
+ b1 , err : = tq .CreateBook (ctx , CreateBookParams {
58
+ AuthorID : a . AuthorID ,
62
59
Isbn : "2" ,
63
60
Title : "the second book" ,
64
61
BookType : BooksBookTypeFICTION ,
65
62
Yr : 2016 ,
66
63
Available : now ,
67
- Tags : "cool, unique" ,
64
+ Tag : " unique" ,
68
65
})
69
66
if err != nil {
70
67
t .Fatal (err )
71
68
}
72
- bookOneID , err := result .LastInsertId ()
73
- if err != nil {
74
- t .Fatal (err )
75
- }
76
69
77
70
// update the title and tags
78
71
err = tq .UpdateBook (ctx , UpdateBookParams {
79
- BookID : int64 ( bookOneID ) ,
72
+ BookID : b1 . BookID ,
80
73
Title : "changed second title" ,
81
- Tags : "cool, disastor" ,
74
+ Tag : " disastor" ,
82
75
})
83
76
if err != nil {
84
77
t .Fatal (err )
85
78
}
86
79
87
80
// save third book
88
81
_ , err = tq .CreateBook (ctx , CreateBookParams {
89
- AuthorID : int64 ( authorID ) ,
82
+ AuthorID : a . AuthorID ,
90
83
Isbn : "3" ,
91
84
Title : "the third book" ,
92
85
BookType : BooksBookTypeFICTION ,
93
86
Yr : 2001 ,
94
87
Available : now ,
95
- Tags : "cool" ,
88
+ Tag : "cool" ,
96
89
})
97
90
if err != nil {
98
91
t .Fatal (err )
99
92
}
100
93
101
94
// save fourth book
102
- result , err = tq .CreateBook (ctx , CreateBookParams {
103
- AuthorID : int64 ( authorID ) ,
95
+ b3 , err : = tq .CreateBook (ctx , CreateBookParams {
96
+ AuthorID : a . AuthorID ,
104
97
Isbn : "4" ,
105
98
Title : "4th place finisher" ,
106
99
BookType : BooksBookTypeFICTION ,
107
100
Yr : 2011 ,
108
101
Available : now ,
109
- Tags : "other" ,
102
+ Tag : "other" ,
110
103
})
111
104
if err != nil {
112
105
t .Fatal (err )
113
106
}
114
- bookThreeID , err := result .LastInsertId ()
115
- if err != nil {
116
- t .Fatal (err )
117
- }
118
107
119
108
// tx commit
120
109
err = tx .Commit ()
@@ -124,10 +113,10 @@ func TestBooks(t *testing.T) {
124
113
125
114
// upsert, changing ISBN and title
126
115
err = dq .UpdateBookISBN (ctx , UpdateBookISBNParams {
127
- BookID : int64 ( bookThreeID ) ,
116
+ BookID : b3 . BookID ,
128
117
Isbn : "NEW ISBN" ,
129
118
Title : "never ever gonna finish, a quatrain" ,
130
- Tags : "someother" ,
119
+ Tag : "someother" ,
131
120
})
132
121
if err != nil {
133
122
t .Fatal (err )
@@ -150,20 +139,20 @@ func TestBooks(t *testing.T) {
150
139
t .Logf ("Book %d author: %s\n " , book .BookID , author .Name )
151
140
}
152
141
153
- // find a book with either "cool" or "other" tag
142
+ // find a book with either "cool" or "other" or "someother" tag
154
143
t .Logf ("---------\n Tag search results:\n " )
155
- res , err := dq .BooksByTags (ctx , "cool" )
144
+ res , err := dq .BooksByTags (ctx , [] string { "cool" , "other" , "someother" } )
156
145
if err != nil {
157
146
t .Fatal (err )
158
147
}
159
148
for _ , ab := range res {
160
- t .Logf ("Book %d: '%s', Author: '%s', ISBN: '%s' Tags : '%v'\n " , ab .BookID , ab .Title , ab .Name , ab .Isbn , ab .Tags )
149
+ t .Logf ("Book %d: '%s', Author: '%s', ISBN: '%s' Tag : '%v'\n " , ab .BookID , ab .Title , ab .Name , ab .Isbn , ab .Tag )
161
150
}
162
151
163
152
// TODO: call say_hello(varchar)
164
153
165
154
// get book 4 and delete
166
- b5 , err := dq .GetBook (ctx , int64 ( bookThreeID ) )
155
+ b5 , err := dq .GetBook (ctx , b3 . BookID )
167
156
if err != nil {
168
157
t .Fatal (err )
169
158
}
0 commit comments