add table prefix and suffix for multi-tenant environment support

This closes #125.
This commit is contained in:
fourdim 2022-03-16 22:47:34 +08:00
parent c29f0afd2b
commit 87cc6c9e93
9 changed files with 100 additions and 0 deletions

View file

@ -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),

View file

@ -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),