MCPcopy
hub / github.com/Masterminds/squirrel / TestInsertBuilderToSql

Function TestInsertBuilderToSql

insert_test.go:9–30  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestInsertBuilderToSql(t *testing.T) {
10 b := Insert("").
11 Prefix("WITH prefix AS ?", 0).
12 Into("a").
13 Options("DELAYED", "IGNORE").
14 Columns("b", "c").
15 Values(1, 2).
16 Values(3, Expr("? + 1", 4)).
17 Suffix("RETURNING ?", 5)
18
19 sql, args, err := b.ToSql()
20 assert.NoError(t, err)
21
22 expectedSQL :=
23 "WITH prefix AS ? " +
24 "INSERT DELAYED IGNORE INTO a (b,c) VALUES (?,?),(?,? + 1) " +
25 "RETURNING ?"
26 assert.Equal(t, expectedSQL, sql)
27
28 expectedArgs := []interface{}{0, 1, 2, 3, 4, 5}
29 assert.Equal(t, expectedArgs, args)
30}
31
32func TestInsertBuilderToSqlErr(t *testing.T) {
33 _, _, err := Insert("").Values(1).ToSql()

Callers

nothing calls this directly

Calls 9

InsertFunction · 0.85
ExprFunction · 0.85
ValuesMethod · 0.80
IntoMethod · 0.80
ToSqlMethod · 0.65
SuffixMethod · 0.45
ColumnsMethod · 0.45
OptionsMethod · 0.45
PrefixMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…