Allow set statements to be used as tables and expressions.
This commit is contained in:
parent
5ad213885f
commit
5de001d7e0
8 changed files with 134 additions and 38 deletions
|
|
@ -36,6 +36,25 @@ func TestSelect_ScanToStruct(t *testing.T) {
|
|||
assert.DeepEqual(t, actor, expectedActor)
|
||||
}
|
||||
|
||||
func TestClassicSelect(t *testing.T) {
|
||||
query := sqlbuilder.SELECT(Payment.AllColumns, Customer.AllColumns).
|
||||
FROM(Payment.INNER_JOIN(Customer, Payment.CustomerID.Eq(Customer.CustomerID))).
|
||||
ORDER_BY(Payment.PaymentID.Asc()).
|
||||
LIMIT(30)
|
||||
|
||||
queryStr, args, err := query.Sql()
|
||||
|
||||
assert.NilError(t, err)
|
||||
fmt.Println(queryStr)
|
||||
fmt.Println(args)
|
||||
|
||||
dest := []model.Payment{}
|
||||
|
||||
err = query.Query(db, &dest)
|
||||
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
func TestSelect_ScanToSlice(t *testing.T) {
|
||||
customers := []model.Customer{}
|
||||
|
||||
|
|
@ -58,6 +77,23 @@ func TestSelect_ScanToSlice(t *testing.T) {
|
|||
assert.DeepEqual(t, lastCustomer, customers[598])
|
||||
}
|
||||
|
||||
func TestSelectAndUnionInProjection(t *testing.T) {
|
||||
|
||||
query := Payment.
|
||||
SELECT(
|
||||
Payment.PaymentID,
|
||||
Customer.SELECT(Customer.CustomerID).LIMIT(1),
|
||||
sqlbuilder.UNION(Payment.SELECT(Payment.PaymentID).LIMIT(1).OFFSET(10), Payment.SELECT(Payment.PaymentID).LIMIT(1).OFFSET(2)).LIMIT(1),
|
||||
).
|
||||
LIMIT(12)
|
||||
|
||||
queryStr, args, err := query.Sql()
|
||||
|
||||
assert.NilError(t, err)
|
||||
fmt.Println(queryStr)
|
||||
fmt.Println(args)
|
||||
}
|
||||
|
||||
//func TestJoinQueryStruct(t *testing.T) {
|
||||
//
|
||||
// query := FilmActor.
|
||||
|
|
@ -253,7 +289,7 @@ func TestSelectFullJoin(t *testing.T) {
|
|||
|
||||
func TestSelectFullCrossJoin(t *testing.T) {
|
||||
query := Customer.
|
||||
CrossJoin(Address).
|
||||
CROSS_JOIN(Address).
|
||||
SELECT(Customer.AllColumns, Address.AllColumns).
|
||||
ORDER_BY(Customer.CustomerID.Asc()).
|
||||
LIMIT(1000)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue