add table prefix and suffix for multi-tenant environment support
This closes #125.
This commit is contained in:
parent
c29f0afd2b
commit
87cc6c9e93
9 changed files with 100 additions and 0 deletions
|
|
@ -42,6 +42,16 @@ func (a ActorTable) FromSchema(schemaName string) *ActorTable {
|
||||||
return newActorTable(schemaName, a.TableName(), a.Alias())
|
return newActorTable(schemaName, a.TableName(), a.Alias())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPrefix creates new ActorTable with assigned table prefix
|
||||||
|
func (a ActorTable) WithPrefix(prefix string) *ActorTable {
|
||||||
|
return newActorTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSuffix creates new ActorTable with assigned table suffix
|
||||||
|
func (a ActorTable) WithSuffix(suffix string) *ActorTable {
|
||||||
|
return newActorTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
func newActorTable(schemaName, tableName, alias string) *ActorTable {
|
func newActorTable(schemaName, tableName, alias string) *ActorTable {
|
||||||
return &ActorTable{
|
return &ActorTable{
|
||||||
actorTable: newActorTableImpl(schemaName, tableName, alias),
|
actorTable: newActorTableImpl(schemaName, tableName, alias),
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,16 @@ func (a CategoryTable) FromSchema(schemaName string) *CategoryTable {
|
||||||
return newCategoryTable(schemaName, a.TableName(), a.Alias())
|
return newCategoryTable(schemaName, a.TableName(), a.Alias())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPrefix creates new CategoryTable with assigned table prefix
|
||||||
|
func (a CategoryTable) WithPrefix(prefix string) *CategoryTable {
|
||||||
|
return newCategoryTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSuffix creates new CategoryTable with assigned table suffix
|
||||||
|
func (a CategoryTable) WithSuffix(suffix string) *CategoryTable {
|
||||||
|
return newCategoryTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
func newCategoryTable(schemaName, tableName, alias string) *CategoryTable {
|
func newCategoryTable(schemaName, tableName, alias string) *CategoryTable {
|
||||||
return &CategoryTable{
|
return &CategoryTable{
|
||||||
categoryTable: newCategoryTableImpl(schemaName, tableName, alias),
|
categoryTable: newCategoryTableImpl(schemaName, tableName, alias),
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,16 @@ func (a FilmTable) FromSchema(schemaName string) *FilmTable {
|
||||||
return newFilmTable(schemaName, a.TableName(), a.Alias())
|
return newFilmTable(schemaName, a.TableName(), a.Alias())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPrefix creates new FilmTable with assigned table prefix
|
||||||
|
func (a FilmTable) WithPrefix(prefix string) *FilmTable {
|
||||||
|
return newFilmTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSuffix creates new FilmTable with assigned table suffix
|
||||||
|
func (a FilmTable) WithSuffix(suffix string) *FilmTable {
|
||||||
|
return newFilmTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
func newFilmTable(schemaName, tableName, alias string) *FilmTable {
|
func newFilmTable(schemaName, tableName, alias string) *FilmTable {
|
||||||
return &FilmTable{
|
return &FilmTable{
|
||||||
filmTable: newFilmTableImpl(schemaName, tableName, alias),
|
filmTable: newFilmTableImpl(schemaName, tableName, alias),
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,16 @@ func (a FilmActorTable) FromSchema(schemaName string) *FilmActorTable {
|
||||||
return newFilmActorTable(schemaName, a.TableName(), a.Alias())
|
return newFilmActorTable(schemaName, a.TableName(), a.Alias())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPrefix creates new FilmActorTable with assigned table prefix
|
||||||
|
func (a FilmActorTable) WithPrefix(prefix string) *FilmActorTable {
|
||||||
|
return newFilmActorTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSuffix creates new FilmActorTable with assigned table suffix
|
||||||
|
func (a FilmActorTable) WithSuffix(suffix string) *FilmActorTable {
|
||||||
|
return newFilmActorTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
func newFilmActorTable(schemaName, tableName, alias string) *FilmActorTable {
|
func newFilmActorTable(schemaName, tableName, alias string) *FilmActorTable {
|
||||||
return &FilmActorTable{
|
return &FilmActorTable{
|
||||||
filmActorTable: newFilmActorTableImpl(schemaName, tableName, alias),
|
filmActorTable: newFilmActorTableImpl(schemaName, tableName, alias),
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,16 @@ func (a FilmCategoryTable) FromSchema(schemaName string) *FilmCategoryTable {
|
||||||
return newFilmCategoryTable(schemaName, a.TableName(), a.Alias())
|
return newFilmCategoryTable(schemaName, a.TableName(), a.Alias())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPrefix creates new FilmCategoryTable with assigned table prefix
|
||||||
|
func (a FilmCategoryTable) WithPrefix(prefix string) *FilmCategoryTable {
|
||||||
|
return newFilmCategoryTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSuffix creates new FilmCategoryTable with assigned table suffix
|
||||||
|
func (a FilmCategoryTable) WithSuffix(suffix string) *FilmCategoryTable {
|
||||||
|
return newFilmCategoryTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
func newFilmCategoryTable(schemaName, tableName, alias string) *FilmCategoryTable {
|
func newFilmCategoryTable(schemaName, tableName, alias string) *FilmCategoryTable {
|
||||||
return &FilmCategoryTable{
|
return &FilmCategoryTable{
|
||||||
filmCategoryTable: newFilmCategoryTableImpl(schemaName, tableName, alias),
|
filmCategoryTable: newFilmCategoryTableImpl(schemaName, tableName, alias),
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,16 @@ func (a LanguageTable) FromSchema(schemaName string) *LanguageTable {
|
||||||
return newLanguageTable(schemaName, a.TableName(), a.Alias())
|
return newLanguageTable(schemaName, a.TableName(), a.Alias())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPrefix creates new LanguageTable with assigned table prefix
|
||||||
|
func (a LanguageTable) WithPrefix(prefix string) *LanguageTable {
|
||||||
|
return newLanguageTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSuffix creates new LanguageTable with assigned table suffix
|
||||||
|
func (a LanguageTable) WithSuffix(suffix string) *LanguageTable {
|
||||||
|
return newLanguageTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
func newLanguageTable(schemaName, tableName, alias string) *LanguageTable {
|
func newLanguageTable(schemaName, tableName, alias string) *LanguageTable {
|
||||||
return &LanguageTable{
|
return &LanguageTable{
|
||||||
languageTable: newLanguageTableImpl(schemaName, tableName, alias),
|
languageTable: newLanguageTableImpl(schemaName, tableName, alias),
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,16 @@ func (a ActorInfoTable) FromSchema(schemaName string) *ActorInfoTable {
|
||||||
return newActorInfoTable(schemaName, a.TableName(), a.Alias())
|
return newActorInfoTable(schemaName, a.TableName(), a.Alias())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPrefix creates new ActorInfoTable with assigned table prefix
|
||||||
|
func (a ActorInfoTable) WithPrefix(prefix string) *ActorInfoTable {
|
||||||
|
return newActorInfoTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSuffix creates new ActorInfoTable with assigned table suffix
|
||||||
|
func (a ActorInfoTable) WithSuffix(suffix string) *ActorInfoTable {
|
||||||
|
return newActorInfoTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
func newActorInfoTable(schemaName, tableName, alias string) *ActorInfoTable {
|
func newActorInfoTable(schemaName, tableName, alias string) *ActorInfoTable {
|
||||||
return &ActorInfoTable{
|
return &ActorInfoTable{
|
||||||
actorInfoTable: newActorInfoTableImpl(schemaName, tableName, alias),
|
actorInfoTable: newActorInfoTableImpl(schemaName, tableName, alias),
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,16 @@ func (a CustomerListTable) FromSchema(schemaName string) *CustomerListTable {
|
||||||
return newCustomerListTable(schemaName, a.TableName(), a.Alias())
|
return newCustomerListTable(schemaName, a.TableName(), a.Alias())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPrefix creates new CustomerListTable with assigned table prefix
|
||||||
|
func (a CustomerListTable) WithPrefix(prefix string) *CustomerListTable {
|
||||||
|
return newCustomerListTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSuffix creates new CustomerListTable with assigned table suffix
|
||||||
|
func (a CustomerListTable) WithSuffix(suffix string) *CustomerListTable {
|
||||||
|
return newCustomerListTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
func newCustomerListTable(schemaName, tableName, alias string) *CustomerListTable {
|
func newCustomerListTable(schemaName, tableName, alias string) *CustomerListTable {
|
||||||
return &CustomerListTable{
|
return &CustomerListTable{
|
||||||
customerListTable: newCustomerListTableImpl(schemaName, tableName, alias),
|
customerListTable: newCustomerListTableImpl(schemaName, tableName, alias),
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,16 @@ func (a {{tableTemplate.TypeName}}) FromSchema(schemaName string) {{tableTemplat
|
||||||
return new{{tableTemplate.TypeName}}(schemaName, a.TableName(), a.Alias())
|
return new{{tableTemplate.TypeName}}(schemaName, a.TableName(), a.Alias())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPrefix creates new {{tableTemplate.TypeName}} with assigned table prefix
|
||||||
|
func (a {{tableTemplate.TypeName}}) WithPrefix(prefix string) {{tableTemplate.TypeName}} {
|
||||||
|
return new{{tableTemplate.TypeName}}(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSuffix creates new {{tableTemplate.TypeName}} with assigned table suffix
|
||||||
|
func (a {{tableTemplate.TypeName}}) WithSuffix(suffix string) {{tableTemplate.TypeName}} {
|
||||||
|
return new{{tableTemplate.TypeName}}(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
func new{{tableTemplate.TypeName}}(schemaName, tableName, alias string) {{tableTemplate.TypeName}} {
|
func new{{tableTemplate.TypeName}}(schemaName, tableName, alias string) {{tableTemplate.TypeName}} {
|
||||||
var (
|
var (
|
||||||
{{- range $i, $c := .Columns}}
|
{{- range $i, $c := .Columns}}
|
||||||
|
|
@ -119,6 +129,16 @@ func (a {{tableTemplate.TypeName}}) FromSchema(schemaName string) *{{tableTempla
|
||||||
return new{{tableTemplate.TypeName}}(schemaName, a.TableName(), a.Alias())
|
return new{{tableTemplate.TypeName}}(schemaName, a.TableName(), a.Alias())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPrefix creates new {{tableTemplate.TypeName}} with assigned table prefix
|
||||||
|
func (a {{tableTemplate.TypeName}}) WithPrefix(prefix string) *{{tableTemplate.TypeName}} {
|
||||||
|
return new{{tableTemplate.TypeName}}(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSuffix creates new {{tableTemplate.TypeName}} with assigned table suffix
|
||||||
|
func (a {{tableTemplate.TypeName}}) WithSuffix(suffix string) *{{tableTemplate.TypeName}} {
|
||||||
|
return new{{tableTemplate.TypeName}}(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||||
|
}
|
||||||
|
|
||||||
func new{{tableTemplate.TypeName}}(schemaName, tableName, alias string) *{{tableTemplate.TypeName}} {
|
func new{{tableTemplate.TypeName}}(schemaName, tableName, alias string) *{{tableTemplate.TypeName}} {
|
||||||
return &{{tableTemplate.TypeName}}{
|
return &{{tableTemplate.TypeName}}{
|
||||||
{{structImplName}}: new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias),
|
{{structImplName}}: new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue