From 87cc6c9e93cc526a611f2258655a16a74a77ace0 Mon Sep 17 00:00:00 2001 From: fourdim Date: Wed, 16 Mar 2022 22:47:34 +0800 Subject: [PATCH] add table prefix and suffix for multi-tenant environment support This closes #125. --- .../.gen/jetdb/dvds/table/actor.go | 10 ++++++++++ .../.gen/jetdb/dvds/table/category.go | 10 ++++++++++ .../quick-start/.gen/jetdb/dvds/table/film.go | 10 ++++++++++ .../.gen/jetdb/dvds/table/film_actor.go | 10 ++++++++++ .../.gen/jetdb/dvds/table/film_category.go | 10 ++++++++++ .../.gen/jetdb/dvds/table/language.go | 10 ++++++++++ .../.gen/jetdb/dvds/view/actor_info.go | 10 ++++++++++ .../.gen/jetdb/dvds/view/customer_list.go | 10 ++++++++++ generator/template/file_templates.go | 20 +++++++++++++++++++ 9 files changed, 100 insertions(+) diff --git a/examples/quick-start/.gen/jetdb/dvds/table/actor.go b/examples/quick-start/.gen/jetdb/dvds/table/actor.go index bbeb7e8f..37e0f85f 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/actor.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/actor.go @@ -42,6 +42,16 @@ func (a ActorTable) FromSchema(schemaName string) *ActorTable { 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 { return &ActorTable{ actorTable: newActorTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/table/category.go b/examples/quick-start/.gen/jetdb/dvds/table/category.go index 563938d9..87beb46d 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/category.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/category.go @@ -41,6 +41,16 @@ func (a CategoryTable) FromSchema(schemaName string) *CategoryTable { 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 { return &CategoryTable{ categoryTable: newCategoryTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/table/film.go b/examples/quick-start/.gen/jetdb/dvds/table/film.go index 65db900a..46364083 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/film.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/film.go @@ -51,6 +51,16 @@ func (a FilmTable) FromSchema(schemaName string) *FilmTable { 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 { return &FilmTable{ filmTable: newFilmTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/table/film_actor.go b/examples/quick-start/.gen/jetdb/dvds/table/film_actor.go index 30c3ad35..7fe60c38 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/film_actor.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/film_actor.go @@ -41,6 +41,16 @@ func (a FilmActorTable) FromSchema(schemaName string) *FilmActorTable { 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 { return &FilmActorTable{ filmActorTable: newFilmActorTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/table/film_category.go b/examples/quick-start/.gen/jetdb/dvds/table/film_category.go index 83681777..fb3bfb65 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/film_category.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/film_category.go @@ -41,6 +41,16 @@ func (a FilmCategoryTable) FromSchema(schemaName string) *FilmCategoryTable { 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 { return &FilmCategoryTable{ filmCategoryTable: newFilmCategoryTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/table/language.go b/examples/quick-start/.gen/jetdb/dvds/table/language.go index 5bddeebb..24f037d7 100644 --- a/examples/quick-start/.gen/jetdb/dvds/table/language.go +++ b/examples/quick-start/.gen/jetdb/dvds/table/language.go @@ -41,6 +41,16 @@ func (a LanguageTable) FromSchema(schemaName string) *LanguageTable { 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 { return &LanguageTable{ languageTable: newLanguageTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/view/actor_info.go b/examples/quick-start/.gen/jetdb/dvds/view/actor_info.go index 5bfa25d3..23f81aa2 100644 --- a/examples/quick-start/.gen/jetdb/dvds/view/actor_info.go +++ b/examples/quick-start/.gen/jetdb/dvds/view/actor_info.go @@ -42,6 +42,16 @@ func (a ActorInfoTable) FromSchema(schemaName string) *ActorInfoTable { 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 { return &ActorInfoTable{ actorInfoTable: newActorInfoTableImpl(schemaName, tableName, alias), diff --git a/examples/quick-start/.gen/jetdb/dvds/view/customer_list.go b/examples/quick-start/.gen/jetdb/dvds/view/customer_list.go index c03a5ef5..cdf14cae 100644 --- a/examples/quick-start/.gen/jetdb/dvds/view/customer_list.go +++ b/examples/quick-start/.gen/jetdb/dvds/view/customer_list.go @@ -47,6 +47,16 @@ func (a CustomerListTable) FromSchema(schemaName string) *CustomerListTable { 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 { return &CustomerListTable{ customerListTable: newCustomerListTableImpl(schemaName, tableName, alias), diff --git a/generator/template/file_templates.go b/generator/template/file_templates.go index e3020cea..d1f12603 100644 --- a/generator/template/file_templates.go +++ b/generator/template/file_templates.go @@ -49,6 +49,16 @@ func (a {{tableTemplate.TypeName}}) FromSchema(schemaName string) {{tableTemplat 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}} { var ( {{- 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()) } +// 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}} { return &{{tableTemplate.TypeName}}{ {{structImplName}}: new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias),