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
|
|
@ -97,7 +97,8 @@ func new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias string) {{st
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
var tableSqlBuilderSetSchemaTemplate = `
|
var tableSqlBuilderSetSchemaTemplate = `package {{package}}
|
||||||
|
|
||||||
func {{setSchemaMethodName}}(schema string) {
|
func {{setSchemaMethodName}}(schema string) {
|
||||||
{{- range .}}
|
{{- range .}}
|
||||||
{{ .InstanceName }} = {{ .InstanceName }}.FromSchema(schema)
|
{{ .InstanceName }} = {{ .InstanceName }}.FromSchema(schema)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package template
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
@ -63,52 +62,6 @@ func processSQLBuilder(dirPath string, dialect jet.Dialect, schemaMetaData metad
|
||||||
processTableSQLBuilder("table", sqlBuilderPath, dialect, schemaMetaData, schemaMetaData.TablesMetaData, sqlBuilderTemplate)
|
processTableSQLBuilder("table", sqlBuilderPath, dialect, schemaMetaData, schemaMetaData.TablesMetaData, sqlBuilderTemplate)
|
||||||
processTableSQLBuilder("view", sqlBuilderPath, dialect, schemaMetaData, schemaMetaData.ViewsMetaData, sqlBuilderTemplate)
|
processTableSQLBuilder("view", sqlBuilderPath, dialect, schemaMetaData, schemaMetaData.ViewsMetaData, sqlBuilderTemplate)
|
||||||
processEnumSQLBuilder(sqlBuilderPath, dialect, schemaMetaData.EnumsMetaData, sqlBuilderTemplate)
|
processEnumSQLBuilder(sqlBuilderPath, dialect, schemaMetaData.EnumsMetaData, sqlBuilderTemplate)
|
||||||
processTableSQLBuilderSetSchema(sqlBuilderPath, schemaMetaData, sqlBuilderTemplate)
|
|
||||||
}
|
|
||||||
|
|
||||||
func processTableSQLBuilderSetSchema(dirPath string, schemaMetadata metadata.Schema, builderTemplate SQLBuilder) {
|
|
||||||
|
|
||||||
var builders []TableSQLBuilder
|
|
||||||
for _, tm := range schemaMetadata.TablesMetaData {
|
|
||||||
|
|
||||||
table := builderTemplate.Table(tm)
|
|
||||||
if table.Skip {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
builders = append(builders, table)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(builders) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err := utils.EnsureDirPath(dirPath)
|
|
||||||
throw.OnError(err)
|
|
||||||
|
|
||||||
fmt.Println("Generating global `SetSchema` method")
|
|
||||||
schemaIdentifier := utils.ToGoIdentifier(schemaMetadata.Name)
|
|
||||||
|
|
||||||
funcPath := path.Join(dirPath, builders[0].Path)
|
|
||||||
|
|
||||||
origText, err := os.ReadFile(path.Join(funcPath, builders[0].FileName+".go"))
|
|
||||||
throw.OnError(err)
|
|
||||||
|
|
||||||
text, err := generateTemplate(
|
|
||||||
tableSqlBuilderSetSchemaTemplate,
|
|
||||||
builders,
|
|
||||||
template.FuncMap{
|
|
||||||
"setSchemaMethodName": func() string {
|
|
||||||
return "Set" + schemaIdentifier + "Schema"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
throw.OnError(err)
|
|
||||||
|
|
||||||
text = append(origText, text...)
|
|
||||||
|
|
||||||
err = utils.SaveGoFile(funcPath, builders[0].FileName, text)
|
|
||||||
throw.OnError(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func processEnumSQLBuilder(dirPath string, dialect jet.Dialect, enumsMetaData []metadata.Enum, sqlBuilder SQLBuilder) {
|
func processEnumSQLBuilder(dirPath string, dialect jet.Dialect, enumsMetaData []metadata.Enum, sqlBuilder SQLBuilder) {
|
||||||
|
|
@ -166,6 +119,8 @@ func processTableSQLBuilder(fileTypes, dirPath string,
|
||||||
|
|
||||||
fmt.Printf("Generating %s sql builder files\n", fileTypes)
|
fmt.Printf("Generating %s sql builder files\n", fileTypes)
|
||||||
|
|
||||||
|
var generatedBuilders []TableSQLBuilder
|
||||||
|
|
||||||
for _, tableMetaData := range tablesMetaData {
|
for _, tableMetaData := range tablesMetaData {
|
||||||
|
|
||||||
var tableSQLBuilder TableSQLBuilder
|
var tableSQLBuilder TableSQLBuilder
|
||||||
|
|
@ -217,7 +172,38 @@ func processTableSQLBuilder(fileTypes, dirPath string,
|
||||||
|
|
||||||
err = utils.SaveGoFile(tableSQLBuilderPath, tableSQLBuilder.FileName, text)
|
err = utils.SaveGoFile(tableSQLBuilderPath, tableSQLBuilder.FileName, text)
|
||||||
throw.OnError(err)
|
throw.OnError(err)
|
||||||
|
|
||||||
|
generatedBuilders = append(generatedBuilders, tableSQLBuilder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(generatedBuilders) > 0 {
|
||||||
|
generateSetSchema(dirPath, fileTypes, schemaMetaData, generatedBuilders)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateSetSchema(dirPath, fileTypes string, schemaMetadata metadata.Schema, builders []TableSQLBuilder) {
|
||||||
|
|
||||||
|
basePath := path.Join(dirPath, builders[0].Path)
|
||||||
|
err := utils.EnsureDirPath(basePath)
|
||||||
|
throw.OnError(err)
|
||||||
|
|
||||||
|
schemaIdentifier := utils.ToGoIdentifier(schemaMetadata.Name)
|
||||||
|
methodName := fmt.Sprintf("Set%sSchema", schemaIdentifier)
|
||||||
|
|
||||||
|
fmt.Printf("Generating global `%s` method for %s\n", methodName, fileTypes)
|
||||||
|
|
||||||
|
text, err := generateTemplate(
|
||||||
|
autoGenWarningTemplate+tableSqlBuilderSetSchemaTemplate,
|
||||||
|
builders,
|
||||||
|
template.FuncMap{
|
||||||
|
"package": func() string { return builders[0].PackageName() },
|
||||||
|
"setSchemaMethodName": func() string { return methodName },
|
||||||
|
},
|
||||||
|
)
|
||||||
|
throw.OnError(err)
|
||||||
|
|
||||||
|
err = utils.SaveGoFile(basePath, fileTypes, text)
|
||||||
|
throw.OnError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertedRowAlias(dialect jet.Dialect) string {
|
func insertedRowAlias(dialect jet.Dialect) string {
|
||||||
|
|
|
||||||
|
|
@ -133,12 +133,12 @@ func TestIgnoreTablesViewsEnums(t *testing.T) {
|
||||||
tableSQLBuilderFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/table")
|
tableSQLBuilderFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/table")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
testutils.AssertFileNamesEqual(t, tableSQLBuilderFiles, "customer.go", "film.go", "film_actor.go",
|
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")
|
viewSQLBuilderFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/view")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
testutils.AssertFileNamesEqual(t, viewSQLBuilderFiles, "nicer_but_slower_film_list.go",
|
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")
|
enumFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/enum")
|
||||||
require.NoError(t, err)
|
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",
|
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",
|
"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/actor.go", actorSQLBuilderFile)
|
||||||
|
testutils.AssertFileContent(t, genTestDir3+"/dvds/table/table.go", tableSetSchemaFile)
|
||||||
|
|
||||||
// View SQL Builder files
|
// View SQL Builder files
|
||||||
viewSQLBuilderFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/view")
|
viewSQLBuilderFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/view")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
testutils.AssertFileNamesEqual(t, viewSQLBuilderFiles, "actor_info.go", "film_list.go", "nicer_but_slower_film_list.go",
|
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/actor_info.go", actorInfoSQLBuilderFile)
|
||||||
|
testutils.AssertFileContent(t, genTestDir3+"/dvds/view/view.go", viewSetSchemaFile)
|
||||||
|
|
||||||
// Enums SQL Builder files
|
// Enums SQL Builder files
|
||||||
enumFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/enum")
|
enumFiles, err := ioutil.ReadDir(genTestDir3 + "/dvds/enum")
|
||||||
|
|
@ -308,6 +310,17 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
|
||||||
MutableColumns: mutableColumns,
|
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) {
|
func SetDvdsSchema(schema string) {
|
||||||
Actor = Actor.FromSchema(schema)
|
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)
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
|
||||||
|
|
@ -153,14 +153,14 @@ func TestGeneratorIgnoreTables(t *testing.T) {
|
||||||
|
|
||||||
testutils.AssertFileNamesEqual(t, tableSQLBuilderFiles, "category.go",
|
testutils.AssertFileNamesEqual(t, tableSQLBuilderFiles, "category.go",
|
||||||
"customer.go", "film_actor.go", "film_category.go", "inventory.go", "language.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
|
// View SQL Builder files
|
||||||
viewSQLBuilderFiles, err := ioutil.ReadDir("./.gentestdata2/jetdb/dvds/view")
|
viewSQLBuilderFiles, err := ioutil.ReadDir("./.gentestdata2/jetdb/dvds/view")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
testutils.AssertFileNamesEqual(t, viewSQLBuilderFiles, "nicer_but_slower_film_list.go",
|
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
|
// Enums SQL Builder files
|
||||||
_, err = ioutil.ReadDir("./.gentestdata2/jetdb/dvds/enum")
|
_, 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",
|
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",
|
"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/actor.go", actorSQLBuilderFile)
|
||||||
|
testutils.AssertFileContent(t, "./.gentestdata2/jetdb/dvds/table/table.go", actorSQLBuilderTableFile)
|
||||||
|
|
||||||
// View SQL Builder files
|
// View SQL Builder files
|
||||||
viewSQLBuilderFiles, err := ioutil.ReadDir("./.gentestdata2/jetdb/dvds/view")
|
viewSQLBuilderFiles, err := ioutil.ReadDir("./.gentestdata2/jetdb/dvds/view")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
testutils.AssertFileNamesEqual(t, viewSQLBuilderFiles, "actor_info.go", "film_list.go", "nicer_but_slower_film_list.go",
|
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/actor_info.go", actorInfoSQLBuilderFile)
|
||||||
|
testutils.AssertFileContent(t, "./.gentestdata2/jetdb/dvds/view/view.go", actorInfoSQLBuilderViewFile)
|
||||||
|
|
||||||
// Enums SQL Builder files
|
// Enums SQL Builder files
|
||||||
enumFiles, err := ioutil.ReadDir("./.gentestdata2/jetdb/dvds/enum")
|
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 = `
|
var actorModelFile = `
|
||||||
//
|
//
|
||||||
// Code generated by go-jet DO NOT EDIT.
|
// 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) {
|
func TestGeneratedAllTypesSQLBuilderFiles(t *testing.T) {
|
||||||
skipForCockroachDB(t)
|
skipForCockroachDB(t)
|
||||||
|
|
||||||
|
|
@ -523,7 +575,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")
|
"person.go", "person_phone.go", "weird_names_table.go", "user.go", "floats.go", "table.go")
|
||||||
|
|
||||||
testutils.AssertFileContent(t, tableDir+"/all_types.go", allTypesTableContent)
|
testutils.AssertFileContent(t, tableDir+"/all_types.go", allTypesTableContent)
|
||||||
}
|
}
|
||||||
|
|
@ -914,15 +966,4 @@ func newAllTypesTableImpl(schemaName, tableName, alias string) allTypesTable {
|
||||||
MutableColumns: mutableColumns,
|
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)
|
|
||||||
}
|
|
||||||
`
|
`
|
||||||
|
|
|
||||||
|
|
@ -92,12 +92,12 @@ func TestCmdGeneratorIgnoreTablesViewsEnums(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
testutils.AssertFileNamesEqual(t, tableSQLBuilderFiles, "country.go",
|
testutils.AssertFileNamesEqual(t, tableSQLBuilderFiles, "country.go",
|
||||||
"customer.go", "film_actor.go", "film_category.go", "film_text.go", "inventory.go", "language.go",
|
"customer.go", "film_actor.go", "film_category.go", "film_text.go", "inventory.go", "language.go",
|
||||||
"payment.go", "staff.go")
|
"payment.go", "staff.go", "table.go")
|
||||||
|
|
||||||
viewSQLBuilderFiles, err := ioutil.ReadDir(genDestDir + "/view")
|
viewSQLBuilderFiles, err := ioutil.ReadDir(genDestDir + "/view")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
testutils.AssertFileNamesEqual(t, viewSQLBuilderFiles, "sales_by_film_category.go",
|
testutils.AssertFileNamesEqual(t, viewSQLBuilderFiles, "sales_by_film_category.go",
|
||||||
"sales_by_store.go")
|
"sales_by_store.go", "view.go")
|
||||||
|
|
||||||
modelFiles, err := ioutil.ReadDir(genDestDir + "/model")
|
modelFiles, err := ioutil.ReadDir(genDestDir + "/model")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -114,18 +114,20 @@ func assertGeneratedFiles(t *testing.T) {
|
||||||
|
|
||||||
testutils.AssertFileNamesEqual(t, tableSQLBuilderFiles, "actor.go", "address.go", "category.go", "city.go", "country.go",
|
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",
|
"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, genDestDir+"/table/actor.go", actorSQLBuilderFile)
|
testutils.AssertFileContent(t, genDestDir+"/table/actor.go", actorSQLBuilderFile)
|
||||||
|
testutils.AssertFileContent(t, genDestDir+"/table/table.go", actorSQLBuilderTableFile)
|
||||||
|
|
||||||
// View SQL Builder files
|
// View SQL Builder files
|
||||||
viewSQLBuilderFiles, err := ioutil.ReadDir(genDestDir + "/view")
|
viewSQLBuilderFiles, err := ioutil.ReadDir(genDestDir + "/view")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
testutils.AssertFileNamesEqual(t, viewSQLBuilderFiles, "film_list.go", "sales_by_film_category.go",
|
testutils.AssertFileNamesEqual(t, viewSQLBuilderFiles, "film_list.go", "sales_by_film_category.go",
|
||||||
"customer_list.go", "sales_by_store.go", "staff_list.go")
|
"customer_list.go", "sales_by_store.go", "staff_list.go", "view.go")
|
||||||
|
|
||||||
testutils.AssertFileContent(t, genDestDir+"/view/film_list.go", filmListSQLBuilderFile)
|
testutils.AssertFileContent(t, genDestDir+"/view/film_list.go", filmListSQLBuilderFile)
|
||||||
|
testutils.AssertFileContent(t, genDestDir+"/view/view.go", filmListSQLBuilderViewFile)
|
||||||
|
|
||||||
// Model files
|
// Model files
|
||||||
modelFiles, err := ioutil.ReadDir(genDestDir + "/model")
|
modelFiles, err := ioutil.ReadDir(genDestDir + "/model")
|
||||||
|
|
@ -225,6 +227,16 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
|
||||||
MutableColumns: mutableColumns,
|
MutableColumns: mutableColumns,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
`
|
||||||
|
const 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 SetSchema(schema string) {
|
func SetSchema(schema string) {
|
||||||
Actor = Actor.FromSchema(schema)
|
Actor = Actor.FromSchema(schema)
|
||||||
|
|
@ -345,6 +357,25 @@ func newFilmListTableImpl(schemaName, tableName, alias string) filmListTable {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const filmListSQLBuilderViewFile = `
|
||||||
|
//
|
||||||
|
// 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 SetSchema(schema string) {
|
||||||
|
CustomerList = CustomerList.FromSchema(schema)
|
||||||
|
FilmList = FilmList.FromSchema(schema)
|
||||||
|
SalesByFilmCategory = SalesByFilmCategory.FromSchema(schema)
|
||||||
|
SalesByStore = SalesByStore.FromSchema(schema)
|
||||||
|
StaffList = StaffList.FromSchema(schema)
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
const addressModelFile = `
|
const addressModelFile = `
|
||||||
//
|
//
|
||||||
// Code generated by go-jet DO NOT EDIT.
|
// Code generated by go-jet DO NOT EDIT.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue