dal/pkg/builder/Builder_test.go
Anton Nesterov 1db30b92c2
[wip] builder
Signed-off-by: Anton Nesterov <anton@demiurg.io>
2024-08-09 21:14:28 +02:00

37 lines
745 B
Go

package builder
import (
"testing"
)
func TestBuilderFind(t *testing.T) {
db := New(SQLiteContext{})
db.In("table t").Find(Query{
"field": "value",
"a": 1,
})
expect := "SELECT * FROM table t WHERE t.a = 1 AND t.field = 'value'"
if db.Sql() != expect {
t.Errorf(`Expected: "%s", Got: %s`, expect, db.Sql())
}
}
func TestBuilderJoin(t *testing.T) {
db := New(SQLiteContext{})
db.In("table t")
db.Find(Query{
"field": "value",
"a": 1,
})
db.Join(Join{
For: "table2 t2",
Do: Query{
"t2.field": "t.field",
},
})
expect := "SELECT * FROM table t JOIN table2 t2 ON t2.field = t.field WHERE t.a = 1 AND t.field = 'value'"
if db.Sql() != expect {
t.Errorf(`Expected: "%s", Got: %s`, expect, db.Sql())
}
}