MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestInsertStatementSQL

Function TestInsertStatementSQL

pkg/sql/ast/sql_test.go:114–156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestInsertStatementSQL(t *testing.T) {
115 tests := []struct {
116 name string
117 stmt *InsertStatement
118 want string
119 }{
120 {
121 name: "simple insert",
122 stmt: &InsertStatement{
123 TableName: "users",
124 Columns: []Expression{&Identifier{Name: "name"}, &Identifier{Name: "email"}},
125 Values: [][]Expression{{&LiteralValue{Value: "Alice", Type: "STRING"}, &LiteralValue{Value: "alice@example.com", Type: "STRING"}}},
126 },
127 want: "INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com')",
128 },
129 {
130 name: "multi-row insert",
131 stmt: &InsertStatement{
132 TableName: "users",
133 Columns: []Expression{&Identifier{Name: "name"}},
134 Values: [][]Expression{{&LiteralValue{Value: "Alice", Type: "STRING"}}, {&LiteralValue{Value: "Bob", Type: "STRING"}}},
135 },
136 want: "INSERT INTO users (name) VALUES ('Alice'), ('Bob')",
137 },
138 {
139 name: "insert with on conflict do nothing",
140 stmt: &InsertStatement{
141 TableName: "users",
142 Columns: []Expression{&Identifier{Name: "email"}},
143 Values: [][]Expression{{&LiteralValue{Value: "a@b.com", Type: "STRING"}}},
144 OnConflict: &OnConflict{Target: []Expression{&Identifier{Name: "email"}}, Action: OnConflictAction{DoNothing: true}},
145 },
146 want: "INSERT INTO users (email) VALUES ('a@b.com') ON CONFLICT (email) DO NOTHING",
147 },
148 }
149 for _, tt := range tests {
150 t.Run(tt.name, func(t *testing.T) {
151 if got := tt.stmt.SQL(); got != tt.want {
152 t.Errorf("SQL() =\n %s\nwant:\n %s", got, tt.want)
153 }
154 })
155 }
156}
157
158func TestUpdateStatementSQL(t *testing.T) {
159 stmt := &UpdateStatement{

Callers

nothing calls this directly

Calls 3

RunMethod · 0.80
ErrorfMethod · 0.65
SQLMethod · 0.45

Tested by

no test coverage detected