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

Function TestTemplateInsert

adapter/postgresql/template_test.go:165–205  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

163}
164
165func TestTemplateInsert(t *testing.T) {
166 b := sqlbuilder.WithTemplate(template)
167 assert := assert.New(t)
168
169 assert.Equal(
170 `INSERT INTO "artist" VALUES ($1, $2), ($3, $4), ($5, $6)`,
171 b.InsertInto("artist").
172 Values(10, "Ryuichi Sakamoto").
173 Values(11, "Alondra de la Parra").
174 Values(12, "Haruki Murakami").
175 String(),
176 )
177
178 assert.Equal(
179 `INSERT INTO "artist" ("id", "name") VALUES ($1, $2)`,
180 b.InsertInto("artist").Values(map[string]string{"id": "12", "name": "Chavela Vargas"}).String(),
181 )
182
183 assert.Equal(
184 `INSERT INTO "artist" ("id", "name") VALUES ($1, $2) RETURNING "id"`,
185 b.InsertInto("artist").Values(map[string]string{"id": "12", "name": "Chavela Vargas"}).Returning("id").String(),
186 )
187
188 assert.Equal(
189 `INSERT INTO "artist" ("id", "name") VALUES ($1, $2)`,
190 b.InsertInto("artist").Values(map[string]interface{}{"name": "Chavela Vargas", "id": 12}).String(),
191 )
192
193 assert.Equal(
194 `INSERT INTO "artist" ("id", "name") VALUES ($1, $2)`,
195 b.InsertInto("artist").Values(struct {
196 ID int `db:"id"`
197 Name string `db:"name"`
198 }{12, "Chavela Vargas"}).String(),
199 )
200
201 assert.Equal(
202 `INSERT INTO "artist" ("name", "id") VALUES ($1, $2)`,
203 b.InsertInto("artist").Columns("name", "id").Values("Chavela Vargas", 12).String(),
204 )
205}
206
207func TestTemplateUpdate(t *testing.T) {
208 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