@@ -6,7 +6,7 @@ A new record can be inserted to database using a struct, map or set function. To
66
77<!-- tabs:start -->
88
9- ### ** main.go **
9+ ### ** Example **
1010
1111``` go
1212book := Book {
@@ -20,7 +20,7 @@ if err := repo.Insert(ctx, &book); err != nil {
2020}
2121```
2222
23- ### ** main_test.go **
23+ ### ** Mock **
2424
2525> reltest.Repository will automatically sets any primary key value to be 1.
2626
@@ -50,7 +50,7 @@ To insert a new record using a map, simply pass a `rel.Map` as the second argume
5050
5151<!-- tabs:start -->
5252
53- ### ** main.go **
53+ ### ** Example **
5454
5555``` go
5656var book Book
@@ -63,7 +63,7 @@ data := rel.Map{
6363repo.Insert (ctx, &book, data)
6464```
6565
66- ### ** main_test.go **
66+ ### ** Mock **
6767
6868> reltest.Repository will automatically populate record using value provided by map.
6969
@@ -81,14 +81,14 @@ It's also possible to insert a new record manually using `rel.Set`, which is a v
8181
8282<!-- tabs:start -->
8383
84- ### ** main.go **
84+ ### ** Example **
8585
8686``` go
8787// Insert using set.
8888repo.Insert (ctx, &book, rel.Set (" title" , " Rel for dummies" ), rel.Set (" category" , " education" ))
8989```
9090
91- ### ** main_test.go **
91+ ### ** Mock **
9292
9393``` go
9494// Expect insertion with given modifier.
@@ -105,14 +105,14 @@ To inserts multiple records at once, use `InsertAll`.
105105
106106<!-- tabs:start -->
107107
108- ### ** main.go **
108+ ### ** Example **
109109
110110``` go
111111// InsertAll books.
112112repo.InsertAll (ctx, &books)
113113```
114114
115- ### ** main_test.go **
115+ ### ** Mock **
116116
117117``` go
118118// Expect any insert all.
@@ -129,16 +129,17 @@ REL provides a powerful API for querying record from database. To query a single
129129
130130<!-- tabs:start -->
131131
132- ### ** main.go **
132+ ### ** Example **
133133
134134``` go
135+ // Retrieve a book with id 1
135136repo.Find (ctx, &book, rel.Eq (" id" , 1 ))
136137
137138// OR: with sugar alias
138139repo.Find (ctx, &book, where.Eq (" id" , 1 ))
139140```
140141
141- ### ** main_test.go **
142+ ### ** Mock **
142143
143144``` go
144145// Expect a find query and mock the result.
@@ -155,13 +156,13 @@ To query multiple records, use `FindAll` method.
155156
156157<!-- tabs:start -->
157158
158- ### ** main.go **
159+ ### ** Example **
159160
160161``` go
161162repo.FindAll (ctx, &books, where.Like (" title" , " %d ummies% " ).AndEq (" category" , " education" ), rel.Limit (10 ))
162163```
163164
164- ### ** main_test.go **
165+ ### ** Mock **
165166
166167``` go
167168// Expect a find all query and mock the result.
@@ -175,14 +176,14 @@ REL also support chainable query api for a more complex query use case.
175176
176177<!-- tabs:start -->
177178
178- ### ** main.go **
179+ ### ** Example **
179180
180181``` go
181182query := rel.Select (" title" , " category" ).Where (where.Eq (" category" , " education" )).SortAsc (" title" )
182183repo.FindAll (ctx, &books, query)
183184```
184185
185- ### ** main_test.go **
186+ ### ** Mock **
186187
187188``` go
188189// Expect a find all query and mock the result.
@@ -200,14 +201,14 @@ Similar to create, updating a record in REL can also be done using struct, map o
200201
201202<!-- tabs:start -->
202203
203- ### ** main.go **
204+ ### ** Example **
204205
205206``` go
206207// Update directly using struct.
207208repo.Update (ctx, &book)
208209```
209210
210- ### ** main_test.go **
211+ ### ** Mock **
211212
212213``` go
213214// Expect any update is called.
@@ -220,14 +221,14 @@ Besides struct, map and set function. There's also increment and decrement modif
220221
221222<!-- tabs:start -->
222223
223- ### ** main.go **
224+ ### ** Example **
224225
225226``` go
226227// Update directly using struct.
227228repo.Update (ctx, &book, rel.Inc (" views" ))
228229```
229230
230- ### ** main_test.go **
231+ ### ** Mock **
231232
232233``` go
233234// Expect any update is called.
@@ -244,14 +245,14 @@ To delete a record in rel, simply pass the record to be deleted.
244245
245246<!-- tabs:start -->
246247
247- ### ** main.go **
248+ ### ** Example **
248249
249250``` go
250251// Delete a record.
251252repo.Delete (ctx, &book)
252253```
253254
254- ### ** main_test.go **
255+ ### ** Mock **
255256
256257``` go
257258// Expect book to be deleted.
@@ -265,14 +266,14 @@ Deleting multiple records is possible using `DeleteAll`.
265266
266267<!-- tabs:start -->
267268
268- ### ** main.go **
269+ ### ** Example **
269270
270271``` go
271272// We have manually define the table here.
272273repo.DeleteAll (ctx, rel.From (" books" ).Where (where.Eq (" id" , 1 )))
273274```
274275
275- ### ** main_test.go **
276+ ### ** Mock **
276277
277278``` go
278279// Expect books to be deleted.
0 commit comments