I use Loopback 4, TypeScript with PostgreSQL DB, I have a requirement to mention the postgresql schema name for the tables,
CREATE TABLE registry.vendors (
id VARCHAR(50) not null default registry.id_generator() PRIMARY KEY,
name VARCHAR (50) UNIQUE NOT NULL
);
Model is defined as below
@model({
name: 'vendors'
// name: 'registry.vendors' not working
})
export class Vendor extends Entity {
@property({
type: 'string',
id: true,
//required: true,
})
id: string;
....
}
Loopback 4 always look for table 'public.vendors' not 'registry', I don't find any documentation on lb4 website https://loopback.io/doc/en/lb4/Model.html related to this, how to explicitly mention the schema name in the model/loopback so that the lookup can be done on schema name, not the default 'public'
@gopalakrishnan-subramani, I believe it is similar to this issue https://github.com/strongloop/loopback-next/issues/2134. You can set the schema name and table name in the settings in your model TS file.
Cross posting my comment :
@model({
settings: {
postgresql: {
table: 'customer',
schema: 'registry' ////////// here is the line
},
},
})
export class Customer2 extends Entity {
For details, please see reference in this docs page: https://loopback.io/doc/en/lb3/Creating-a-database-schema-from-models.html
@dhmlau,
Thank you so much, it solved the issues.
Closing the issue.
Hi, @dhmlau is it possible to specify what Postgres schema to use for queries at runtime? I have a use case where after authorization, I get the schema name from the user object and that would determine what schema on my Postgres DB to query. I'm building a multi-tenant application.
is it possible to specify what Postgres schema to use for queries at runtime? I have a use case where after authorization, I get the schema name from the user object and that would determine what schema on my Postgres DB to query. I'm building a multi-tenant application.
I opened a new issue to discuss this use case and posted few ideas what to try.
Most helpful comment
@gopalakrishnan-subramani, I believe it is similar to this issue https://github.com/strongloop/loopback-next/issues/2134. You can set the schema name and table name in the
settingsin your model TS file.Cross posting my comment :
For details, please see reference in this docs page: https://loopback.io/doc/en/lb3/Creating-a-database-schema-from-models.html