MySQL refactor.
This commit is contained in:
parent
8519ccbdd0
commit
4fbf576370
36 changed files with 1080 additions and 270 deletions
|
|
@ -257,36 +257,6 @@ LIMIT ?;
|
|||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
func TestSelectINTERSECT(t *testing.T) {
|
||||
defer func() {
|
||||
r := recover()
|
||||
assert.Equal(t, r, "jet: MySQL does not support INTERSECT operator.")
|
||||
}()
|
||||
|
||||
query := Payment.SELECT(Payment.PaymentID).LIMIT(1).OFFSET(10).
|
||||
INTERSECT(Payment.SELECT(Payment.PaymentID).LIMIT(1).OFFSET(2)).LIMIT(1)
|
||||
|
||||
//fmt.Println(query.DebugSql())
|
||||
|
||||
err := query.Query(db, &struct{}{})
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
func TestSelectEXCEPT(t *testing.T) {
|
||||
defer func() {
|
||||
r := recover()
|
||||
assert.Equal(t, r, "jet: MySQL does not support EXCEPT operator.")
|
||||
}()
|
||||
|
||||
query := Payment.SELECT(Payment.PaymentID).LIMIT(1).OFFSET(10).
|
||||
EXCEPT(Payment.SELECT(Payment.PaymentID).LIMIT(1).OFFSET(2)).LIMIT(1)
|
||||
|
||||
//fmt.Println(query.DebugSql())
|
||||
|
||||
err := query.Query(db, &struct{}{})
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
func TestSelectUNION_ALL(t *testing.T) {
|
||||
expectedSQL := `
|
||||
(
|
||||
|
|
@ -303,21 +273,29 @@ func TestSelectUNION_ALL(t *testing.T) {
|
|||
LIMIT ?
|
||||
OFFSET ?
|
||||
)
|
||||
);
|
||||
)
|
||||
ORDER BY "payment.payment_id"
|
||||
LIMIT ?
|
||||
OFFSET ?;
|
||||
`
|
||||
query := UNION_ALL(
|
||||
Payment.SELECT(Payment.PaymentID).LIMIT(1).OFFSET(10),
|
||||
Payment.SELECT(Payment.PaymentID).LIMIT(1).OFFSET(2),
|
||||
)
|
||||
).ORDER_BY(Payment.PaymentID).
|
||||
LIMIT(4).
|
||||
OFFSET(3)
|
||||
|
||||
//fmt.Println(query.Sql())
|
||||
|
||||
testutils.AssertStatementSql(t, query, expectedSQL, int64(1), int64(10), int64(1), int64(2))
|
||||
testutils.AssertStatementSql(t, query, expectedSQL, int64(1), int64(10), int64(1), int64(2), int64(4), int64(3))
|
||||
|
||||
query2 := Payment.SELECT(Payment.PaymentID).LIMIT(1).OFFSET(10).
|
||||
UNION_ALL(Payment.SELECT(Payment.PaymentID).LIMIT(1).OFFSET(2))
|
||||
UNION_ALL(Payment.SELECT(Payment.PaymentID).LIMIT(1).OFFSET(2)).
|
||||
ORDER_BY(Payment.PaymentID).
|
||||
LIMIT(4).
|
||||
OFFSET(3)
|
||||
|
||||
testutils.AssertStatementSql(t, query2, expectedSQL, int64(1), int64(10), int64(1), int64(2))
|
||||
testutils.AssertStatementSql(t, query2, expectedSQL, int64(1), int64(10), int64(1), int64(2), int64(4), int64(3))
|
||||
|
||||
err := query.Query(db, &struct{}{})
|
||||
assert.NilError(t, err)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package mysql
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-jet/jet/internal/testutils"
|
||||
. "github.com/go-jet/jet/mysql"
|
||||
"github.com/go-jet/jet/tests/.gentestdata/mysql/test_sample/model"
|
||||
|
|
@ -21,10 +22,12 @@ func TestUpdateValues(t *testing.T) {
|
|||
|
||||
var expectedSQL = `
|
||||
UPDATE test_sample.link
|
||||
SET name = 'Bong', url = 'http://bong.com'
|
||||
SET name = 'Bong',
|
||||
url = 'http://bong.com'
|
||||
WHERE link.name = 'Bing';
|
||||
`
|
||||
|
||||
fmt.Println(query.DebugSql())
|
||||
testutils.AssertDebugStatementSql(t, query, expectedSQL, "Bong", "http://bong.com", "Bing")
|
||||
|
||||
testutils.AssertExec(t, query, db)
|
||||
|
|
@ -61,34 +64,21 @@ func TestUpdateWithSubQueries(t *testing.T) {
|
|||
expectedSQL := `
|
||||
UPDATE test_sample.link
|
||||
SET name = (
|
||||
SELECT ?
|
||||
), url = (
|
||||
SELECT link2.url AS "link2.url"
|
||||
FROM test_sample.link2
|
||||
WHERE link2.name = ?
|
||||
)
|
||||
SELECT ?
|
||||
),
|
||||
url = (
|
||||
SELECT link2.url AS "link2.url"
|
||||
FROM test_sample.link2
|
||||
WHERE link2.name = ?
|
||||
)
|
||||
WHERE link.name = ?;
|
||||
`
|
||||
fmt.Println(query.Sql())
|
||||
testutils.AssertStatementSql(t, query, expectedSQL, "Bong", "Youtube", "Bing")
|
||||
|
||||
testutils.AssertExec(t, query, db)
|
||||
}
|
||||
|
||||
func TestUpdateAndReturning(t *testing.T) {
|
||||
defer func() {
|
||||
r := recover()
|
||||
assert.Equal(t, r, "jet: MySQL dialect does not support RETURNING.")
|
||||
}()
|
||||
|
||||
stmt := Link.
|
||||
UPDATE(Link.Name, Link.URL).
|
||||
SET("DuckDuckGo", "http://www.duckduckgo.com").
|
||||
WHERE(Link.Name.EQ(String("Ask"))).
|
||||
RETURNING(Link.AllColumns)
|
||||
|
||||
stmt.Query(db, &struct{}{})
|
||||
}
|
||||
|
||||
func TestUpdateWithModelData(t *testing.T) {
|
||||
setupLinkTableForUpdateTest(t)
|
||||
|
||||
|
|
@ -105,9 +95,13 @@ func TestUpdateWithModelData(t *testing.T) {
|
|||
|
||||
expectedSQL := `
|
||||
UPDATE test_sample.link
|
||||
SET id = ?, url = ?, name = ?, description = ?
|
||||
SET id = ?,
|
||||
url = ?,
|
||||
name = ?,
|
||||
description = ?
|
||||
WHERE link.id = ?;
|
||||
`
|
||||
fmt.Println(stmt.Sql())
|
||||
testutils.AssertStatementSql(t, stmt, expectedSQL, int32(201), "http://www.duckduckgo.com", "DuckDuckGo", nil, int64(201))
|
||||
|
||||
testutils.AssertExec(t, stmt, db)
|
||||
|
|
@ -132,7 +126,9 @@ func TestUpdateWithModelDataAndPredefinedColumnList(t *testing.T) {
|
|||
|
||||
var expectedSQL = `
|
||||
UPDATE test_sample.link
|
||||
SET description = NULL, name = 'DuckDuckGo', url = 'http://www.duckduckgo.com'
|
||||
SET description = NULL,
|
||||
name = 'DuckDuckGo',
|
||||
url = 'http://www.duckduckgo.com'
|
||||
WHERE link.id = 201;
|
||||
`
|
||||
//fmt.Println(stmt.DebugSql())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue