Renamed generated SetSchema to Set<SchemaName>Schema
This commit is contained in:
parent
471499ea00
commit
a792fe6e0a
3 changed files with 33 additions and 7 deletions
|
|
@ -98,7 +98,7 @@ func new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias string) {{st
|
|||
`
|
||||
|
||||
var tableSqlBuilderSetSchemaTemplate = `
|
||||
func SetSchema(schema string) {
|
||||
func {{setSchemaMethodName}}(schema string) {
|
||||
{{- range .}}
|
||||
{{ .InstanceName }} = {{ .InstanceName }}.FromSchema(schema)
|
||||
{{- end}}
|
||||
|
|
|
|||
|
|
@ -63,11 +63,11 @@ func processSQLBuilder(dirPath string, dialect jet.Dialect, schemaMetaData metad
|
|||
processTableSQLBuilder("table", sqlBuilderPath, dialect, schemaMetaData, schemaMetaData.TablesMetaData, sqlBuilderTemplate)
|
||||
processTableSQLBuilder("view", sqlBuilderPath, dialect, schemaMetaData, schemaMetaData.ViewsMetaData, sqlBuilderTemplate)
|
||||
processEnumSQLBuilder(sqlBuilderPath, dialect, schemaMetaData.EnumsMetaData, sqlBuilderTemplate)
|
||||
processTableSQLBuilderSetSchema(sqlBuilderPath, schemaMetaData.TablesMetaData, sqlBuilderTemplate)
|
||||
processTableSQLBuilderSetSchema(sqlBuilderPath, schemaMetaData, sqlBuilderTemplate)
|
||||
}
|
||||
|
||||
func processTableSQLBuilderSetSchema(dirPath string, tablesMetadata []metadata.Table, builderTemplate SQLBuilder) {
|
||||
if len(tablesMetadata) == 0 {
|
||||
func processTableSQLBuilderSetSchema(dirPath string, schemaMetadata metadata.Schema, builderTemplate SQLBuilder) {
|
||||
if schemaMetadata.IsEmpty() {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -77,10 +77,12 @@ func processTableSQLBuilderSetSchema(dirPath string, tablesMetadata []metadata.T
|
|||
throw.OnError(err)
|
||||
|
||||
var builders []TableSQLBuilder
|
||||
for _, tm := range tablesMetadata {
|
||||
for _, tm := range schemaMetadata.TablesMetaData {
|
||||
builders = append(builders, builderTemplate.Table(tm))
|
||||
}
|
||||
|
||||
schemaIdentifier := utils.ToGoIdentifier(schemaMetadata.Name)
|
||||
|
||||
funcPath := path.Join(dirPath, builders[0].Path)
|
||||
|
||||
origText, err := os.ReadFile(path.Join(funcPath, builders[0].FileName+".go"))
|
||||
|
|
@ -89,7 +91,11 @@ func processTableSQLBuilderSetSchema(dirPath string, tablesMetadata []metadata.T
|
|||
text, err := generateTemplate(
|
||||
tableSqlBuilderSetSchemaTemplate,
|
||||
builders,
|
||||
nil,
|
||||
template.FuncMap{
|
||||
"setSchemaMethodName": func() string {
|
||||
return "Set" + schemaIdentifier + "Schema"
|
||||
},
|
||||
},
|
||||
)
|
||||
throw.OnError(err)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@ import (
|
|||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/go-jet/jet/v2/generator/mysql"
|
||||
"github.com/go-jet/jet/v2/internal/testutils"
|
||||
"github.com/go-jet/jet/v2/tests/dbconfig"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const genTestDirRoot = "./.gentestdata3"
|
||||
|
|
@ -307,6 +308,25 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
|
|||
MutableColumns: mutableColumns,
|
||||
}
|
||||
}
|
||||
|
||||
func SetDvdsSchema(schema string) {
|
||||
Actor = Actor.FromSchema(schema)
|
||||
Address = Address.FromSchema(schema)
|
||||
Category = Category.FromSchema(schema)
|
||||
City = City.FromSchema(schema)
|
||||
Country = Country.FromSchema(schema)
|
||||
Customer = Customer.FromSchema(schema)
|
||||
Film = Film.FromSchema(schema)
|
||||
FilmActor = FilmActor.FromSchema(schema)
|
||||
FilmCategory = FilmCategory.FromSchema(schema)
|
||||
FilmText = FilmText.FromSchema(schema)
|
||||
Inventory = Inventory.FromSchema(schema)
|
||||
Language = Language.FromSchema(schema)
|
||||
Payment = Payment.FromSchema(schema)
|
||||
Rental = Rental.FromSchema(schema)
|
||||
Staff = Staff.FromSchema(schema)
|
||||
Store = Store.FromSchema(schema)
|
||||
}
|
||||
`
|
||||
|
||||
var actorModelFile = `
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue