Made 'SetSchema' to be generated in a dedicated file for views and tables.
This commit is contained in:
parent
199bb2a20a
commit
7db99b10bc
5 changed files with 164 additions and 72 deletions
|
|
@ -153,14 +153,14 @@ func TestGeneratorIgnoreTables(t *testing.T) {
|
|||
|
||||
testutils.AssertFileNamesEqual(t, tableSQLBuilderFiles, "category.go",
|
||||
"customer.go", "film_actor.go", "film_category.go", "inventory.go", "language.go",
|
||||
"payment.go", "rental.go", "staff.go", "store.go")
|
||||
"payment.go", "rental.go", "staff.go", "store.go", "table.go")
|
||||
|
||||
// View SQL Builder files
|
||||
viewSQLBuilderFiles, err := ioutil.ReadDir("./.gentestdata2/jetdb/dvds/view")
|
||||
require.NoError(t, err)
|
||||
|
||||
testutils.AssertFileNamesEqual(t, viewSQLBuilderFiles, "nicer_but_slower_film_list.go",
|
||||
"sales_by_film_category.go", "customer_list.go", "sales_by_store.go")
|
||||
"sales_by_film_category.go", "customer_list.go", "sales_by_store.go", "view.go")
|
||||
|
||||
// Enums SQL Builder files
|
||||
_, err = ioutil.ReadDir("./.gentestdata2/jetdb/dvds/enum")
|
||||
|
|
@ -241,18 +241,20 @@ func assertGeneratedFiles(t *testing.T) {
|
|||
|
||||
testutils.AssertFileNamesEqual(t, tableSQLBuilderFiles, "actor.go", "address.go", "category.go", "city.go", "country.go",
|
||||
"customer.go", "film.go", "film_actor.go", "film_category.go", "inventory.go", "language.go",
|
||||
"payment.go", "rental.go", "staff.go", "store.go")
|
||||
"payment.go", "rental.go", "staff.go", "store.go", "table.go")
|
||||
|
||||
testutils.AssertFileContent(t, "./.gentestdata2/jetdb/dvds/table/actor.go", actorSQLBuilderFile)
|
||||
testutils.AssertFileContent(t, "./.gentestdata2/jetdb/dvds/table/table.go", actorSQLBuilderTableFile)
|
||||
|
||||
// View SQL Builder files
|
||||
viewSQLBuilderFiles, err := ioutil.ReadDir("./.gentestdata2/jetdb/dvds/view")
|
||||
require.NoError(t, err)
|
||||
|
||||
testutils.AssertFileNamesEqual(t, viewSQLBuilderFiles, "actor_info.go", "film_list.go", "nicer_but_slower_film_list.go",
|
||||
"sales_by_film_category.go", "customer_list.go", "sales_by_store.go", "staff_list.go")
|
||||
"sales_by_film_category.go", "customer_list.go", "sales_by_store.go", "staff_list.go", "view.go")
|
||||
|
||||
testutils.AssertFileContent(t, "./.gentestdata2/jetdb/dvds/view/actor_info.go", actorInfoSQLBuilderFile)
|
||||
testutils.AssertFileContent(t, "./.gentestdata2/jetdb/dvds/view/view.go", actorInfoSQLBuilderViewFile)
|
||||
|
||||
// Enums SQL Builder files
|
||||
enumFiles, err := ioutil.ReadDir("./.gentestdata2/jetdb/dvds/enum")
|
||||
|
|
@ -388,6 +390,35 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
|
|||
}
|
||||
`
|
||||
|
||||
var actorSQLBuilderTableFile = `
|
||||
//
|
||||
// Code generated by go-jet DO NOT EDIT.
|
||||
//
|
||||
// WARNING: Changes to this file may cause incorrect behavior
|
||||
// and will be lost if the code is regenerated
|
||||
//
|
||||
|
||||
package table
|
||||
|
||||
func SetDvdsSchema(schema string) {
|
||||
Film = Film.FromSchema(schema)
|
||||
Address = Address.FromSchema(schema)
|
||||
Actor = Actor.FromSchema(schema)
|
||||
Category = Category.FromSchema(schema)
|
||||
City = City.FromSchema(schema)
|
||||
Country = Country.FromSchema(schema)
|
||||
Customer = Customer.FromSchema(schema)
|
||||
FilmActor = FilmActor.FromSchema(schema)
|
||||
FilmCategory = FilmCategory.FromSchema(schema)
|
||||
Inventory = Inventory.FromSchema(schema)
|
||||
Language = Language.FromSchema(schema)
|
||||
Rental = Rental.FromSchema(schema)
|
||||
Staff = Staff.FromSchema(schema)
|
||||
Payment = Payment.FromSchema(schema)
|
||||
Store = Store.FromSchema(schema)
|
||||
}
|
||||
`
|
||||
|
||||
var actorModelFile = `
|
||||
//
|
||||
// Code generated by go-jet DO NOT EDIT.
|
||||
|
|
@ -497,6 +528,27 @@ func newActorInfoTableImpl(schemaName, tableName, alias string) actorInfoTable {
|
|||
}
|
||||
`
|
||||
|
||||
var actorInfoSQLBuilderViewFile = `
|
||||
//
|
||||
// Code generated by go-jet DO NOT EDIT.
|
||||
//
|
||||
// WARNING: Changes to this file may cause incorrect behavior
|
||||
// and will be lost if the code is regenerated
|
||||
//
|
||||
|
||||
package view
|
||||
|
||||
func SetDvdsSchema(schema string) {
|
||||
ActorInfo = ActorInfo.FromSchema(schema)
|
||||
CustomerList = CustomerList.FromSchema(schema)
|
||||
FilmList = FilmList.FromSchema(schema)
|
||||
NicerButSlowerFilmList = NicerButSlowerFilmList.FromSchema(schema)
|
||||
SalesByFilmCategory = SalesByFilmCategory.FromSchema(schema)
|
||||
SalesByStore = SalesByStore.FromSchema(schema)
|
||||
StaffList = StaffList.FromSchema(schema)
|
||||
}
|
||||
`
|
||||
|
||||
func TestGeneratedAllTypesSQLBuilderFiles(t *testing.T) {
|
||||
skipForCockroachDB(t)
|
||||
|
||||
|
|
@ -523,7 +575,7 @@ func TestGeneratedAllTypesSQLBuilderFiles(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
testutils.AssertFileNamesEqual(t, tableFiles, "all_types.go", "employee.go", "link.go",
|
||||
"person.go", "person_phone.go", "weird_names_table.go", "user.go", "floats.go")
|
||||
"person.go", "person_phone.go", "weird_names_table.go", "user.go", "floats.go", "table.go")
|
||||
|
||||
testutils.AssertFileContent(t, tableDir+"/all_types.go", allTypesTableContent)
|
||||
}
|
||||
|
|
@ -914,15 +966,4 @@ func newAllTypesTableImpl(schemaName, tableName, alias string) allTypesTable {
|
|||
MutableColumns: mutableColumns,
|
||||
}
|
||||
}
|
||||
|
||||
func SetTestSampleSchema(schema string) {
|
||||
AllTypes = AllTypes.FromSchema(schema)
|
||||
Link = Link.FromSchema(schema)
|
||||
Employee = Employee.FromSchema(schema)
|
||||
Person = Person.FromSchema(schema)
|
||||
PersonPhone = PersonPhone.FromSchema(schema)
|
||||
WeirdNamesTable = WeirdNamesTable.FromSchema(schema)
|
||||
User = User.FromSchema(schema)
|
||||
Floats = Floats.FromSchema(schema)
|
||||
}
|
||||
`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue