Renamed generated schema func to UseSchema.

This commit is contained in:
Jay 2022-12-05 17:26:52 +05:30
parent 04c1a51ba7
commit 1bf48d640a
6 changed files with 46 additions and 41 deletions

View file

@ -322,10 +322,10 @@ var tableSetSchemaFile = `
package table
// UseDvdsSchema changes all global tables/views with the value returned
// UseSchema changes all global tables/views with the value returned
// returned by calling FromSchema on them. Passing an empty string to this function
// will cause queries to be generated without any table/view alias.
func UseDvdsSchema(schema string) {
func UseSchema(schema string) {
Actor = Actor.FromSchema(schema)
Address = Address.FromSchema(schema)
Category = Category.FromSchema(schema)
@ -463,10 +463,10 @@ var viewSetSchemaFile = `
package view
// UseDvdsSchema changes all global tables/views with the value returned
// UseSchema changes all global tables/views with the value returned
// returned by calling FromSchema on them. Passing an empty string to this function
// will cause queries to be generated without any table/view alias.
func UseDvdsSchema(schema string) {
func UseSchema(schema string) {
ActorInfo = ActorInfo.FromSchema(schema)
CustomerList = CustomerList.FromSchema(schema)
FilmList = FilmList.FromSchema(schema)

View file

@ -0,0 +1,25 @@
package mysql
import (
"testing"
"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"
)
func TestUpdateWithJoin(t *testing.T) {
statement := Staff.INNER_JOIN(Address, Address.AddressID.EQ(Staff.AddressID)).
UPDATE(Staff.LastName).
SET(String("New staff name")).
WHERE(Staff.StaffID.EQ(Int(1)))
testutils.AssertStatementSql(t, statement, `
UPDATE dvds.staff
INNER JOIN dvds.address ON (address.address_id = staff.address_id)
SET last_name = ?
WHERE staff.staff_id = ?;
`, "New staff name", int64(1))
testutils.AssertExecAndRollback(t, statement, db)
}

View file

@ -3,14 +3,15 @@ package mysql
import (
"context"
"database/sql"
"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"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/go-jet/jet/v2/internal/testutils"
. "github.com/go-jet/jet/v2/mysql"
"github.com/go-jet/jet/v2/tests/.gentestdata/mysql/test_sample/model"
. "github.com/go-jet/jet/v2/tests/.gentestdata/mysql/test_sample/table"
)
func TestUpdateValues(t *testing.T) {
@ -259,22 +260,6 @@ func TestUpdateExecContext(t *testing.T) {
require.Error(t, err, "context deadline exceeded")
}
func TestUpdateWithJoin(t *testing.T) {
statement := Staff.INNER_JOIN(Address, Address.AddressID.EQ(Staff.AddressID)).
UPDATE(Staff.LastName).
SET(String("New staff name")).
WHERE(Staff.StaffID.EQ(Int(1)))
testutils.AssertStatementSql(t, statement, `
UPDATE dvds.staff
INNER JOIN dvds.address ON (address.address_id = staff.address_id)
SET last_name = ?
WHERE staff.staff_id = ?;
`, "New staff name", int64(1))
testutils.AssertExecAndRollback(t, statement, db)
}
func TestUpdateOptimizerHints(t *testing.T) {
stmt := Link.UPDATE(Link.AllColumns).