Move back to test_sample
This commit is contained in:
parent
a4191b4953
commit
a1088ead17
5 changed files with 77 additions and 19 deletions
|
|
@ -47,7 +47,6 @@ jet-gen-postgres:
|
||||||
jet -dsn=postgres://jet:jet@localhost:50901/jetdb?sslmode=disable -schema=chinook2 -path=./.gentestdata/
|
jet -dsn=postgres://jet:jet@localhost:50901/jetdb?sslmode=disable -schema=chinook2 -path=./.gentestdata/
|
||||||
jet -dsn=postgres://jet:jet@localhost:50901/jetdb?sslmode=disable -schema=northwind -path=./.gentestdata/
|
jet -dsn=postgres://jet:jet@localhost:50901/jetdb?sslmode=disable -schema=northwind -path=./.gentestdata/
|
||||||
jet -dsn=postgres://jet:jet@localhost:50901/jetdb?sslmode=disable -schema=test_sample -path=./.gentestdata/
|
jet -dsn=postgres://jet:jet@localhost:50901/jetdb?sslmode=disable -schema=test_sample -path=./.gentestdata/
|
||||||
jet -dsn=postgres://jet:jet@localhost:50901/jetdb?sslmode=disable -schema=test_generated -path=./.gentestdata/
|
|
||||||
|
|
||||||
jet-gen-mysql:
|
jet-gen-mysql:
|
||||||
jet -source=mysql -dsn="jet:jet@tcp(localhost:50902)/dvds" -path=./.gentestdata/mysql
|
jet -source=mysql -dsn="jet:jet@tcp(localhost:50902)/dvds" -path=./.gentestdata/mysql
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,6 @@ func initPostgresDB(dbType string, connectionString string) {
|
||||||
"test_sample",
|
"test_sample",
|
||||||
"chinook",
|
"chinook",
|
||||||
"chinook2",
|
"chinook2",
|
||||||
"test_generated",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, schemaName := range schemaNames {
|
for _, schemaName := range schemaNames {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
package postgres
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "github.com/go-jet/jet/v2/tests/.gentestdata/jetdb/test_generated/table"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestMutableColumnsExcludeGeneratedColumn(t *testing.T) {
|
|
||||||
t.Run("should not have the generated column in mutableColumns", func(t *testing.T) {
|
|
||||||
require.Equal(t, 2, len(People.MutableColumns))
|
|
||||||
require.Equal(t, People.PeopleName, People.MutableColumns[0])
|
|
||||||
require.Equal(t, People.PeopleHeightCm, People.MutableColumns[1])
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
@ -573,7 +573,7 @@ func TestGeneratedAllTypesSQLBuilderFiles(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
testutils.AssertFileNamesEqual(t, modelFiles, "all_types.go", "all_types_view.go", "employee.go", "link.go",
|
testutils.AssertFileNamesEqual(t, modelFiles, "all_types.go", "all_types_view.go", "employee.go", "link.go",
|
||||||
"mood.go", "person.go", "person_phone.go", "weird_names_table.go", "level.go", "user.go", "floats.go")
|
"mood.go", "person.go", "person_phone.go", "weird_names_table.go", "level.go", "user.go", "floats.go", "people.go")
|
||||||
|
|
||||||
testutils.AssertFileContent(t, modelDir+"/all_types.go", allTypesModelContent)
|
testutils.AssertFileContent(t, modelDir+"/all_types.go", allTypesModelContent)
|
||||||
|
|
||||||
|
|
@ -581,7 +581,7 @@ func TestGeneratedAllTypesSQLBuilderFiles(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
testutils.AssertFileNamesEqual(t, tableFiles, "all_types.go", "employee.go", "link.go",
|
testutils.AssertFileNamesEqual(t, tableFiles, "all_types.go", "employee.go", "link.go",
|
||||||
"person.go", "person_phone.go", "weird_names_table.go", "user.go", "floats.go", "table.go")
|
"person.go", "person_phone.go", "weird_names_table.go", "user.go", "floats.go", "table.go", "people.go")
|
||||||
|
|
||||||
testutils.AssertFileContent(t, tableDir+"/all_types.go", allTypesTableContent)
|
testutils.AssertFileContent(t, tableDir+"/all_types.go", allTypesTableContent)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -476,3 +476,78 @@ FROM test_sample."User";
|
||||||
]
|
]
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMutableColumnsExcludeGeneratedColumn(t *testing.T) {
|
||||||
|
// clean up
|
||||||
|
_, err := People.DELETE().WHERE(People.PeopleID.GT(Int(3))).Exec(db)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
t.Run("should not have the generated column in mutableColumns", func(t *testing.T) {
|
||||||
|
require.Equal(t, 2, len(People.MutableColumns))
|
||||||
|
require.Equal(t, People.PeopleName, People.MutableColumns[0])
|
||||||
|
require.Equal(t, People.PeopleHeightCm, People.MutableColumns[1])
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should query with all columns", func(t *testing.T) {
|
||||||
|
query := SELECT(
|
||||||
|
People.AllColumns,
|
||||||
|
).FROM(
|
||||||
|
People,
|
||||||
|
).WHERE(
|
||||||
|
People.PeopleID.EQ(Int(3)),
|
||||||
|
)
|
||||||
|
|
||||||
|
var result model.People
|
||||||
|
|
||||||
|
err := query.Query(db, &result)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, "Carla", result.PeopleName)
|
||||||
|
require.Equal(t, 155., *result.PeopleHeightCm)
|
||||||
|
require.InEpsilon(t, 61.02, *result.PeopleHeightIn, 1e-3)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should insert without generated columns", func(t *testing.T) {
|
||||||
|
insertQuery := People.INSERT(
|
||||||
|
People.MutableColumns,
|
||||||
|
).MODEL(
|
||||||
|
model.People{
|
||||||
|
PeopleName: "Dario",
|
||||||
|
PeopleHeightCm: testutils.Float64Ptr(120),
|
||||||
|
},
|
||||||
|
).RETURNING(
|
||||||
|
People.MutableColumns,
|
||||||
|
)
|
||||||
|
|
||||||
|
testutils.AssertDebugStatementSql(t, insertQuery, `
|
||||||
|
INSERT INTO test_sample.people (people_name, people_height_cm)
|
||||||
|
VALUES ('Dario', 120)
|
||||||
|
RETURNING people.people_name AS "people.people_name",
|
||||||
|
people.people_height_cm AS "people.people_height_cm";
|
||||||
|
`)
|
||||||
|
|
||||||
|
var result model.People
|
||||||
|
err := insertQuery.Query(db, &result)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, "Dario", result.PeopleName)
|
||||||
|
require.Equal(t, 120., *result.PeopleHeightCm)
|
||||||
|
|
||||||
|
query := SELECT(
|
||||||
|
People.AllColumns,
|
||||||
|
).FROM(
|
||||||
|
People,
|
||||||
|
).ORDER_BY(
|
||||||
|
People.PeopleID.DESC(),
|
||||||
|
).LIMIT(1)
|
||||||
|
|
||||||
|
result = model.People{}
|
||||||
|
|
||||||
|
err = query.Query(db, &result)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, "Dario", result.PeopleName)
|
||||||
|
require.Equal(t, 120., *result.PeopleHeightCm)
|
||||||
|
require.InEpsilon(t, 47.24, *result.PeopleHeightIn, 1e-3)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue