Add more UseSchema tests.

Rename newly generated file to avoid potentional conflict with tables named table or views named view.
This commit is contained in:
go-jet 2023-04-02 13:58:44 +02:00
parent a9aa25416a
commit 5e34bef288
10 changed files with 250 additions and 160 deletions

View file

@ -99,9 +99,8 @@ func new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias string) {{st
var tableSqlBuilderSetSchemaTemplate = `package {{package}}
// 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.
// UseSchema sets a new schema name for all generated {{type}} SQL builder types. It is recommended to invoke
// this method only once at the beginning of the program.
func UseSchema(schema string) {
{{- range .}}
{{ .InstanceName }} = {{ .InstanceName }}.FromSchema(schema)

View file

@ -183,19 +183,20 @@ func processTableSQLBuilder(fileTypes, dirPath string,
func generateUseSchemaFunc(dirPath, fileTypes string, builders []TableSQLBuilder) {
basePath := path.Join(dirPath, builders[0].Path)
fmt.Printf("Generating global `UseSchema` method for %s\n", fileTypes)
text, err := generateTemplate(
autoGenWarningTemplate+tableSqlBuilderSetSchemaTemplate,
builders,
template.FuncMap{
"package": func() string { return builders[0].PackageName() },
"type": func() string { return fileTypes },
},
)
throw.OnError(err)
err = utils.SaveGoFile(basePath, fileTypes, text)
basePath := path.Join(dirPath, builders[0].Path)
fileName := fileTypes + "_use_schema"
err = utils.SaveGoFile(basePath, fileName, text)
throw.OnError(err)
}