github.com/acoshift/pgsql@v0.15.3/pgstmt/delete_test.go (about) 1 package pgstmt_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/acoshift/pgsql/pgstmt" 9 ) 10 11 func TestDelete(t *testing.T) { 12 t.Parallel() 13 14 q, args := pgstmt.Delete(func(b pgstmt.DeleteStatement) { 15 b.From("users") 16 b.Where(func(b pgstmt.Cond) { 17 b.Eq("username", "test") 18 b.Eq("is_active", false) 19 b.Or(func(b pgstmt.Cond) { 20 b.Gt("age", pgstmt.Arg(20)) 21 b.Le("age", pgstmt.Arg(30)) 22 }) 23 }) 24 b.Returning("id", "name") 25 }).SQL() 26 27 assert.Equal(t, 28 "delete from users where (username = $1 and is_active = $2) or (age > $3 and age <= $4) returning id, name", 29 q, 30 ) 31 assert.EqualValues(t, 32 []any{"test", false, 20, 30}, 33 args, 34 ) 35 }