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 = `
|
var tableSqlBuilderSetSchemaTemplate = `
|
||||||
func SetSchema(schema string) {
|
func {{setSchemaMethodName}}(schema string) {
|
||||||
{{- range .}}
|
{{- range .}}
|
||||||
{{ .InstanceName }} = {{ .InstanceName }}.FromSchema(schema)
|
{{ .InstanceName }} = {{ .InstanceName }}.FromSchema(schema)
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,11 @@ 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.TablesMetaData, sqlBuilderTemplate)
|
processTableSQLBuilderSetSchema(sqlBuilderPath, schemaMetaData, sqlBuilderTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func processTableSQLBuilderSetSchema(dirPath string, tablesMetadata []metadata.Table, builderTemplate SQLBuilder) {
|
func processTableSQLBuilderSetSchema(dirPath string, schemaMetadata metadata.Schema, builderTemplate SQLBuilder) {
|
||||||
if len(tablesMetadata) == 0 {
|
if schemaMetadata.IsEmpty() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,10 +77,12 @@ func processTableSQLBuilderSetSchema(dirPath string, tablesMetadata []metadata.T
|
||||||
throw.OnError(err)
|
throw.OnError(err)
|
||||||
|
|
||||||
var builders []TableSQLBuilder
|
var builders []TableSQLBuilder
|
||||||
for _, tm := range tablesMetadata {
|
for _, tm := range schemaMetadata.TablesMetaData {
|
||||||
builders = append(builders, builderTemplate.Table(tm))
|
builders = append(builders, builderTemplate.Table(tm))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
schemaIdentifier := utils.ToGoIdentifier(schemaMetadata.Name)
|
||||||
|
|
||||||
funcPath := path.Join(dirPath, builders[0].Path)
|
funcPath := path.Join(dirPath, builders[0].Path)
|
||||||
|
|
||||||
origText, err := os.ReadFile(path.Join(funcPath, builders[0].FileName+".go"))
|
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(
|
text, err := generateTemplate(
|
||||||
tableSqlBuilderSetSchemaTemplate,
|
tableSqlBuilderSetSchemaTemplate,
|
||||||
builders,
|
builders,
|
||||||
nil,
|
template.FuncMap{
|
||||||
|
"setSchemaMethodName": func() string {
|
||||||
|
return "Set" + schemaIdentifier + "Schema"
|
||||||
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
throw.OnError(err)
|
throw.OnError(err)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,11 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/go-jet/jet/v2/generator/mysql"
|
"github.com/go-jet/jet/v2/generator/mysql"
|
||||||
"github.com/go-jet/jet/v2/internal/testutils"
|
"github.com/go-jet/jet/v2/internal/testutils"
|
||||||
"github.com/go-jet/jet/v2/tests/dbconfig"
|
"github.com/go-jet/jet/v2/tests/dbconfig"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const genTestDirRoot = "./.gentestdata3"
|
const genTestDirRoot = "./.gentestdata3"
|
||||||
|
|
@ -307,6 +308,25 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
|
||||||
MutableColumns: mutableColumns,
|
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 = `
|
var actorModelFile = `
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue