add delete query

This commit is contained in:
2026-07-07 20:07:15 +01:00
parent b302622d0a
commit 1585f945a4
3 changed files with 171 additions and 55 deletions
+47
View File
@@ -0,0 +1,47 @@
package simql
import (
"testing"
"github.com/alecthomas/assert/v2"
)
func TestDelete(t *testing.T) {
type TestCase struct {
In *DeleteQuery
Args []any
String string
}
testCases := []TestCase{
{
In: Delete("customer"),
String: "delete from customer",
},
{
In: Delete("customer as c"),
String: "delete from customer as c",
},
{
In: Delete("customer as c"),
String: "select c.id, c.name from customer as c",
},
{
In: Delete("customer").Where("id = ?", 1234),
Args: []any{1234},
String: "delete from customer where id = ?",
},
{
In: Delete("customer as c").Where("c.id = ?", 1234),
Args: []any{1234},
String: "delete from customer as c where c.id = ?",
},
}
for _, testCase := range testCases {
t.Run(testCase.String, func(t *testing.T) {
assert.Equal(t, testCase.Args, testCase.In.Args(), "collected arguments incorrectly")
assert.Equal(t, testCase.String, testCase.In.String(), "stringified incorrectly")
})
}
}