Changed SetSchema to UseSchema
This commit is contained in:
parent
3f9ae1cabb
commit
04c1a51ba7
5 changed files with 33 additions and 12 deletions
|
|
@ -99,7 +99,10 @@ func new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias string) {{st
|
||||||
|
|
||||||
var tableSqlBuilderSetSchemaTemplate = `package {{package}}
|
var tableSqlBuilderSetSchemaTemplate = `package {{package}}
|
||||||
|
|
||||||
func {{setSchemaMethodName}}(schema string) {
|
// {{schemaMethodName}} changes all global tables/views with the value returned
|
||||||
|
// returned by calling FromSchema on them. Passing an empty string to this function
|
||||||
|
// will cause queries to be generated without any table/view alias.
|
||||||
|
func {{schemaMethodName}}(schema string) {
|
||||||
{{- range .}}
|
{{- range .}}
|
||||||
{{ .InstanceName }} = {{ .InstanceName }}.FromSchema(schema)
|
{{ .InstanceName }} = {{ .InstanceName }}.FromSchema(schema)
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
|
||||||
|
|
@ -177,16 +177,16 @@ func processTableSQLBuilder(fileTypes, dirPath string,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(generatedBuilders) > 0 {
|
if len(generatedBuilders) > 0 {
|
||||||
generateSetSchema(dirPath, fileTypes, schemaMetaData, generatedBuilders)
|
generateUseSchemaFunc(dirPath, fileTypes, schemaMetaData, generatedBuilders)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateSetSchema(dirPath, fileTypes string, schemaMetadata metadata.Schema, builders []TableSQLBuilder) {
|
func generateUseSchemaFunc(dirPath, fileTypes string, schemaMetadata metadata.Schema, builders []TableSQLBuilder) {
|
||||||
|
|
||||||
basePath := path.Join(dirPath, builders[0].Path)
|
basePath := path.Join(dirPath, builders[0].Path)
|
||||||
|
|
||||||
schemaIdentifier := utils.ToGoIdentifier(schemaMetadata.Name)
|
schemaIdentifier := utils.ToGoIdentifier(schemaMetadata.Name)
|
||||||
methodName := fmt.Sprintf("Set%sSchema", schemaIdentifier)
|
methodName := fmt.Sprintf("Use%sSchema", schemaIdentifier)
|
||||||
|
|
||||||
fmt.Printf("Generating global `%s` method for %s\n", methodName, fileTypes)
|
fmt.Printf("Generating global `%s` method for %s\n", methodName, fileTypes)
|
||||||
|
|
||||||
|
|
@ -194,8 +194,8 @@ func generateSetSchema(dirPath, fileTypes string, schemaMetadata metadata.Schema
|
||||||
autoGenWarningTemplate+tableSqlBuilderSetSchemaTemplate,
|
autoGenWarningTemplate+tableSqlBuilderSetSchemaTemplate,
|
||||||
builders,
|
builders,
|
||||||
template.FuncMap{
|
template.FuncMap{
|
||||||
"package": func() string { return builders[0].PackageName() },
|
"package": func() string { return builders[0].PackageName() },
|
||||||
"setSchemaMethodName": func() string { return methodName },
|
"schemaMethodName": func() string { return methodName },
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
throw.OnError(err)
|
throw.OnError(err)
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,10 @@ var tableSetSchemaFile = `
|
||||||
|
|
||||||
package table
|
package table
|
||||||
|
|
||||||
func SetDvdsSchema(schema string) {
|
// UseDvdsSchema changes all global tables/views with the value returned
|
||||||
|
// returned by calling FromSchema on them. Passing an empty string to this function
|
||||||
|
// will cause queries to be generated without any table/view alias.
|
||||||
|
func UseDvdsSchema(schema string) {
|
||||||
Actor = Actor.FromSchema(schema)
|
Actor = Actor.FromSchema(schema)
|
||||||
Address = Address.FromSchema(schema)
|
Address = Address.FromSchema(schema)
|
||||||
Category = Category.FromSchema(schema)
|
Category = Category.FromSchema(schema)
|
||||||
|
|
@ -460,7 +463,10 @@ var viewSetSchemaFile = `
|
||||||
|
|
||||||
package view
|
package view
|
||||||
|
|
||||||
func SetDvdsSchema(schema string) {
|
// UseDvdsSchema changes all global tables/views with the value returned
|
||||||
|
// returned by calling FromSchema on them. Passing an empty string to this function
|
||||||
|
// will cause queries to be generated without any table/view alias.
|
||||||
|
func UseDvdsSchema(schema string) {
|
||||||
ActorInfo = ActorInfo.FromSchema(schema)
|
ActorInfo = ActorInfo.FromSchema(schema)
|
||||||
CustomerList = CustomerList.FromSchema(schema)
|
CustomerList = CustomerList.FromSchema(schema)
|
||||||
FilmList = FilmList.FromSchema(schema)
|
FilmList = FilmList.FromSchema(schema)
|
||||||
|
|
|
||||||
|
|
@ -400,7 +400,10 @@ var actorSQLBuilderTableFile = `
|
||||||
|
|
||||||
package table
|
package table
|
||||||
|
|
||||||
func SetDvdsSchema(schema string) {
|
// UseDvdsSchema changes all global tables/views with the value returned
|
||||||
|
// returned by calling FromSchema on them. Passing an empty string to this function
|
||||||
|
// will cause queries to be generated without any table/view alias.
|
||||||
|
func UseDvdsSchema(schema string) {
|
||||||
Film = Film.FromSchema(schema)
|
Film = Film.FromSchema(schema)
|
||||||
Address = Address.FromSchema(schema)
|
Address = Address.FromSchema(schema)
|
||||||
Actor = Actor.FromSchema(schema)
|
Actor = Actor.FromSchema(schema)
|
||||||
|
|
@ -538,7 +541,10 @@ var actorInfoSQLBuilderViewFile = `
|
||||||
|
|
||||||
package view
|
package view
|
||||||
|
|
||||||
func SetDvdsSchema(schema string) {
|
// UseDvdsSchema changes all global tables/views with the value returned
|
||||||
|
// returned by calling FromSchema on them. Passing an empty string to this function
|
||||||
|
// will cause queries to be generated without any table/view alias.
|
||||||
|
func UseDvdsSchema(schema string) {
|
||||||
ActorInfo = ActorInfo.FromSchema(schema)
|
ActorInfo = ActorInfo.FromSchema(schema)
|
||||||
CustomerList = CustomerList.FromSchema(schema)
|
CustomerList = CustomerList.FromSchema(schema)
|
||||||
FilmList = FilmList.FromSchema(schema)
|
FilmList = FilmList.FromSchema(schema)
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,10 @@ const actorSQLBuilderTableFile = `
|
||||||
|
|
||||||
package table
|
package table
|
||||||
|
|
||||||
func SetSchema(schema string) {
|
// UseSchema changes all global tables/views with the value returned
|
||||||
|
// returned by calling FromSchema on them. Passing an empty string to this function
|
||||||
|
// will cause queries to be generated without any table/view alias.
|
||||||
|
func UseSchema(schema string) {
|
||||||
Actor = Actor.FromSchema(schema)
|
Actor = Actor.FromSchema(schema)
|
||||||
Address = Address.FromSchema(schema)
|
Address = Address.FromSchema(schema)
|
||||||
Category = Category.FromSchema(schema)
|
Category = Category.FromSchema(schema)
|
||||||
|
|
@ -367,7 +370,10 @@ const filmListSQLBuilderViewFile = `
|
||||||
|
|
||||||
package view
|
package view
|
||||||
|
|
||||||
func SetSchema(schema string) {
|
// UseSchema changes all global tables/views with the value returned
|
||||||
|
// returned by calling FromSchema on them. Passing an empty string to this function
|
||||||
|
// will cause queries to be generated without any table/view alias.
|
||||||
|
func UseSchema(schema string) {
|
||||||
CustomerList = CustomerList.FromSchema(schema)
|
CustomerList = CustomerList.FromSchema(schema)
|
||||||
FilmList = FilmList.FromSchema(schema)
|
FilmList = FilmList.FromSchema(schema)
|
||||||
SalesByFilmCategory = SalesByFilmCategory.FromSchema(schema)
|
SalesByFilmCategory = SalesByFilmCategory.FromSchema(schema)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue