jet/delete_statement_test.go

26 lines
661 B
Go
Raw Normal View History

2019-06-21 13:56:57 +02:00
package jet
2019-04-20 19:49:29 +02:00
import (
"testing"
)
func TestDeleteUnconditionally(t *testing.T) {
2019-06-16 11:20:44 +02:00
assertStatementErr(t, table1.DELETE(), `deleting without a WHERE clause`)
assertStatementErr(t, table1.DELETE().WHERE(nil), `deleting without a WHERE clause`)
2019-04-20 19:49:29 +02:00
}
func TestDeleteWithWhere(t *testing.T) {
2019-06-16 11:20:44 +02:00
assertStatement(t, table1.DELETE().WHERE(table1Col1.EQ(Int(1))), `
2019-05-12 18:15:23 +02:00
DELETE FROM db.table1
WHERE table1.col1 = $1;
2019-06-16 11:20:44 +02:00
`, int64(1))
2019-04-20 19:49:29 +02:00
}
func TestDeleteWithWhereAndReturning(t *testing.T) {
assertStatement(t, table1.DELETE().WHERE(table1Col1.EQ(Int(1))).RETURNING(table1Col1), `
DELETE FROM db.table1
WHERE table1.col1 = $1
RETURNING table1.col1 AS "table1.col1";
`, int64(1))
}