MCPcopy Index your code
hub / github.com/upper/db / TestTemplateInsert

Function TestTemplateInsert

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

Source from the content-addressed store, hash-verified

147}
148
149func TestTemplateInsert(t *testing.T) {
150 b := sqlbuilder.WithTemplate(template)
151 assert := assert.New(t)
152
153 assert.Equal(
154 `INSERT INTO "artist" VALUES ($1, $2), ($3, $4), ($5, $6)`,
155 b.InsertInto("artist").
156 Values(10, "Ryuichi Sakamoto").
157 Values(11, "Alondra de la Parra").
158 Values(12, "Haruki Murakami").
159 String(),
160 )
161
162 assert.Equal(
163 `INSERT INTO "artist" ("id", "name") VALUES ($1, $2)`,
164 b.InsertInto("artist").Values(map[string]string{"id": "12", "name": "Chavela Vargas"}).String(),
165 )
166
167 assert.Equal(
168 `INSERT INTO "artist" ("id", "name") VALUES ($1, $2) RETURNING "id"`,
169 b.InsertInto("artist").Values(map[string]string{"id": "12", "name": "Chavela Vargas"}).Returning("id").String(),
170 )
171
172 assert.Equal(
173 `INSERT INTO "artist" ("id", "name") VALUES ($1, $2)`,
174 b.InsertInto("artist").Values(map[string]interface{}{"name": "Chavela Vargas", "id": 12}).String(),
175 )
176
177 assert.Equal(
178 `INSERT INTO "artist" ("id", "name") VALUES ($1, $2)`,
179 b.InsertInto("artist").Values(struct {
180 ID int `db:"id"`
181 Name string `db:"name"`
182 }{12, "Chavela Vargas"}).String(),
183 )
184
185 assert.Equal(
186 `INSERT INTO "artist" ("name", "id") VALUES ($1, $2)`,
187 b.InsertInto("artist").Columns("name", "id").Values("Chavela Vargas", 12).String(),
188 )
189}
190
191func TestTemplateUpdate(t *testing.T) {
192 b := sqlbuilder.WithTemplate(template)

Callers

nothing calls this directly

Calls 7

WithTemplateFunction · 0.92
NewMethod · 0.65
StringMethod · 0.65
ValuesMethod · 0.65
InsertIntoMethod · 0.65
ReturningMethod · 0.65
ColumnsMethod · 0.65

Tested by

no test coverage detected