Schema rename support

- Support for renaming table schemas
 * Table support for renaming schema
 * Empty schema name is left out (using default schema for the
   database connection)
 * Generated code support for obtaining a version of the table with
   renamed schema, similarly as the `AS` function works
 * Unit tests for setting and clearing the schema name
This commit is contained in:
Joonas Haapsaari 2020-08-18 15:47:10 +03:00
parent 4b0263112f
commit b7bcb3527e
3 changed files with 76 additions and 2 deletions

View file

@ -41,6 +41,15 @@ type {{.GoStructName}} struct {
func (a *{{.GoStructName}}) AS(alias string) {{.GoStructName}} {
aliasTable := new{{.GoStructName}}()
aliasTable.Table.AS(alias)
aliasTable.Table.Schema(a.Table.SchemaName())
return aliasTable
}
// Schema creates new {{.GoStructName}} with assigned schema name
func (a *{{.GoStructName}}) Schema(schemaName string) {{.GoStructName}} {
aliasTable := new{{.GoStructName}}()
aliasTable.Table.AS(a.Table.Alias())
aliasTable.Table.Schema(schemaName)
return aliasTable
}
@ -104,6 +113,15 @@ type {{.GoStructName}} struct {
func (a *{{.GoStructName}}) AS(alias string) *{{.GoStructName}} {
aliasTable := new{{.GoStructName}}()
aliasTable.Table.AS(alias)
aliasTable.Table.Schema(a.Table.SchemaName())
return aliasTable
}
// Schema creates new {{.GoStructName}} with assigned schema name
func (a *{{.GoStructName}}) Schema(schemaName string) *{{.GoStructName}} {
aliasTable := new{{.GoStructName}}()
aliasTable.Table.AS(a.Table.Alias())
aliasTable.Table.Schema(schemaName)
return aliasTable
}