Replies: 1 comment
-
Hi, I'm not sure how your final queries looks like, let me point some possibilities:
In your DBConnection class will be a property with the tenant Id you want to refer, and the expression class DBConnection extends PostgreSqlConnection<'DBConnection'> {
tenantId: string
protected escape(identifier: string, strict: boolean): string {
identifier = identifier.replace('{tenantId}', this.tenantId)
return super.escape(identifier, strict)
}
constructor(tenantId: string, queryRunner: QueryRunner) {
super(queryRunner)
this.tenantId = tenantId
}
} Then when you map your tables, you put const tCompany = new class TCompany extends Table<DBConnection, 'TCompany'> {
id = this.autogeneratedPrimaryKey('id', 'int')
name = this.column('name', 'string')
parentId = this.optionalColumn('parent_id', 'int')
constructor() {
super('{tenantId}.company'); // table name in the database
}
}() Then, when you want to create the DBConnection instance, you will need to provide the tenant Id you want to refer. Please let me know if the information here answer your question and share some feedback on it. |
Beta Was this translation helpful? Give feedback.
-
Hello,
How to do CRUD to a table for a specific schema ?
I am building SAAS product with schema isolation method
each tenant has their own schema, but all those schemas has the same structure
thank you
Beta Was this translation helpful? Give feedback.
All reactions