Add USING clause support for DELETE statements
This commit is contained in:
parent
72e8d7d584
commit
60ffd004c5
6 changed files with 134 additions and 11 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"github.com/go-jet/jet/v2/internal/testutils"
|
||||
. "github.com/go-jet/jet/v2/mysql"
|
||||
"github.com/go-jet/jet/v2/tests/.gentestdata/mysql/dvds/table"
|
||||
"github.com/go-jet/jet/v2/tests/.gentestdata/mysql/test_sample/model"
|
||||
. "github.com/go-jet/jet/v2/tests/.gentestdata/mysql/test_sample/table"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -91,3 +92,29 @@ func initForDeleteTest(t *testing.T) {
|
|||
|
||||
testutils.AssertExec(t, stmt, db, 2)
|
||||
}
|
||||
|
||||
func TestDeleteWithUsing(t *testing.T) {
|
||||
tx := beginTx(t)
|
||||
defer tx.Rollback()
|
||||
|
||||
stmt := table.Rental.DELETE().
|
||||
USING(
|
||||
table.Rental.
|
||||
INNER_JOIN(table.Staff, table.Rental.StaffID.EQ(table.Staff.StaffID)),
|
||||
table.Actor,
|
||||
).WHERE(
|
||||
table.Staff.StaffID.EQ(Int(2)).
|
||||
AND(table.Rental.RentalID.LT(Int(10))),
|
||||
)
|
||||
|
||||
testutils.AssertStatementSql(t, stmt, `
|
||||
DELETE FROM dvds.rental
|
||||
USING dvds.rental
|
||||
INNER JOIN dvds.staff ON (rental.staff_id = staff.staff_id),
|
||||
dvds.actor
|
||||
WHERE (staff.staff_id = ?) AND (rental.rental_id < ?);
|
||||
`)
|
||||
|
||||
_, err := stmt.Exec(tx)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue