MCPcopy Create free account
hub / github.com/upper/db / TestTemplateUpdate

Function TestTemplateUpdate

adapter/sqlite/template_test.go:191–231  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

189}
190
191func TestTemplateUpdate(t *testing.T) {
192 b := sqlbuilder.WithTemplate(template)
193 assert := assert.New(t)
194
195 assert.Equal(
196 `UPDATE "artist" SET "name" = $1`,
197 b.Update("artist").Set("name", "Artist").String(),
198 )
199
200 assert.Equal(
201 `UPDATE "artist" SET "name" = $1 WHERE ("id" < $2)`,
202 b.Update("artist").Set("name = ?", "Artist").Where("id <", 5).String(),
203 )
204
205 assert.Equal(
206 `UPDATE "artist" SET "name" = $1 WHERE ("id" < $2)`,
207 b.Update("artist").Set(map[string]string{"name": "Artist"}).Where(db.Cond{"id <": 5}).String(),
208 )
209
210 assert.Equal(
211 `UPDATE "artist" SET "name" = $1 WHERE ("id" < $2)`,
212 b.Update("artist").Set(struct {
213 Nombre string `db:"name"`
214 }{"Artist"}).Where(db.Cond{"id <": 5}).String(),
215 )
216
217 assert.Equal(
218 `UPDATE "artist" SET "name" = $1, "last_name" = $2 WHERE ("id" < $3)`,
219 b.Update("artist").Set(struct {
220 Nombre string `db:"name"`
221 }{"Artist"}).Set(map[string]string{"last_name": "Foo"}).Where(db.Cond{"id <": 5}).String(),
222 )
223
224 assert.Equal(
225 `UPDATE "artist" SET "name" = $1 || ' ' || $2 || id, "id" = id + $3 WHERE (id > $4)`,
226 b.Update("artist").Set(
227 "name = ? || ' ' || ? || id", "Artist", "#",
228 "id = id + ?", 10,
229 ).Where("id > ?", 0).String(),
230 )
231}
232
233func TestTemplateDelete(t *testing.T) {
234 b := sqlbuilder.WithTemplate(template)

Callers

nothing calls this directly

Calls 6

WithTemplateFunction · 0.92
NewMethod · 0.65
StringMethod · 0.65
SetMethod · 0.65
UpdateMethod · 0.65
WhereMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…