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

Function TestUpdate

pkg/sql/ast/dml_test.go:299–394  ·  view source on GitHub ↗

Test Update node (DML)

(t *testing.T)

Source from the content-addressed store, hash-verified

297
298// Test Update node (DML)
299func TestUpdate(t *testing.T) {
300 tests := []struct {
301 name string
302 upd *Update
303 wantLiteral string
304 minChildren int
305 }{
306 {
307 name: "simple UPDATE",
308 upd: &Update{
309 Table: TableReference{Name: "users"},
310 Updates: []UpdateExpression{
311 {
312 Column: &Identifier{Name: "email"},
313 Value: &LiteralValue{Value: "new@example.com"},
314 },
315 },
316 },
317 wantLiteral: "UPDATE",
318 minChildren: 2,
319 },
320 {
321 name: "UPDATE with multiple columns",
322 upd: &Update{
323 Table: TableReference{Name: "users"},
324 Updates: []UpdateExpression{
325 {
326 Column: &Identifier{Name: "name"},
327 Value: &LiteralValue{Value: "John"},
328 },
329 {
330 Column: &Identifier{Name: "age"},
331 Value: &LiteralValue{Value: "30"},
332 },
333 },
334 },
335 wantLiteral: "UPDATE",
336 minChildren: 3,
337 },
338 {
339 name: "UPDATE with WHERE",
340 upd: &Update{
341 Table: TableReference{Name: "users"},
342 Updates: []UpdateExpression{
343 {
344 Column: &Identifier{Name: "status"},
345 Value: &LiteralValue{Value: "inactive"},
346 },
347 },
348 Where: &BinaryExpression{
349 Left: &Identifier{Name: "id"},
350 Operator: "=",
351 Right: &LiteralValue{Value: "10"},
352 },
353 },
354 wantLiteral: "UPDATE",
355 minChildren: 3,
356 },

Callers

nothing calls this directly

Calls 5

RunMethod · 0.80
TokenLiteralMethod · 0.65
ErrorfMethod · 0.65
ChildrenMethod · 0.65
statementNodeMethod · 0.65

Tested by

no test coverage detected