Made 'SetSchema' to be generated in a dedicated file for views and tables.

This commit is contained in:
Jay 2022-12-02 23:02:44 +05:30
parent 199bb2a20a
commit 7db99b10bc
5 changed files with 164 additions and 72 deletions

View file

@ -133,12 +133,12 @@ func TestIgnoreTablesViewsEnums(t *testing.T) {
tableSQLBuilderFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/table")
require.NoError(t, err)
testutils.AssertFileNamesEqual(t, tableSQLBuilderFiles, "customer.go", "film.go", "film_actor.go",
"film_category.go", "film_text.go", "inventory.go", "language.go", "payment.go")
"film_category.go", "film_text.go", "inventory.go", "language.go", "payment.go", "table.go")
viewSQLBuilderFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/view")
require.NoError(t, err)
testutils.AssertFileNamesEqual(t, viewSQLBuilderFiles, "nicer_but_slower_film_list.go",
"sales_by_film_category.go", "sales_by_store.go", "staff_list.go")
"sales_by_film_category.go", "sales_by_store.go", "staff_list.go", "view.go")
enumFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/enum")
require.NoError(t, err)
@ -162,18 +162,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", "film_text.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, genTestDir3+"/dvds/table/actor.go", actorSQLBuilderFile)
testutils.AssertFileContent(t, genTestDir3+"/dvds/table/table.go", tableSetSchemaFile)
// View SQL Builder files
viewSQLBuilderFiles, err := ioutil.ReadDir(genTestDir3 + "/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, genTestDir3+"/dvds/view/actor_info.go", actorInfoSQLBuilderFile)
testutils.AssertFileContent(t, genTestDir3+"/dvds/view/view.go", viewSetSchemaFile)
// Enums SQL Builder files
enumFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/enum")
@ -308,6 +310,17 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
MutableColumns: mutableColumns,
}
}
`
var tableSetSchemaFile = `
//
// 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) {
Actor = Actor.FromSchema(schema)
@ -437,3 +450,23 @@ func newActorInfoTableImpl(schemaName, tableName, alias string) actorInfoTable {
}
}
`
var viewSetSchemaFile = `
//
// 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)
}
`