Postgres: Use another schema other than 'public'
This commit is contained in:
parent
7bbd460f86
commit
1ffab7f5d6
|
@ -27,6 +27,7 @@ module PostgresModule {
|
||||||
database: string
|
database: string
|
||||||
user: string
|
user: string
|
||||||
password: string
|
password: string
|
||||||
|
schema: string
|
||||||
ssl?: boolean
|
ssl?: boolean
|
||||||
ca?: string
|
ca?: string
|
||||||
rejectUnauthorized?: boolean
|
rejectUnauthorized?: boolean
|
||||||
|
@ -64,6 +65,11 @@ module PostgresModule {
|
||||||
default: "root",
|
default: "root",
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
schema: {
|
||||||
|
type: DatasourceFieldTypes.STRING,
|
||||||
|
default: "public",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
ssl: {
|
ssl: {
|
||||||
type: DatasourceFieldTypes.BOOLEAN,
|
type: DatasourceFieldTypes.BOOLEAN,
|
||||||
default: false,
|
default: false,
|
||||||
|
@ -137,8 +143,7 @@ module PostgresModule {
|
||||||
private readonly client: any
|
private readonly client: any
|
||||||
private readonly config: PostgresConfig
|
private readonly config: PostgresConfig
|
||||||
|
|
||||||
COLUMNS_SQL =
|
COLUMNS_SQL!: string
|
||||||
"select * from information_schema.columns where not table_schema = 'information_schema' and not table_schema = 'pg_catalog'"
|
|
||||||
|
|
||||||
PRIMARY_KEYS_SQL = `
|
PRIMARY_KEYS_SQL = `
|
||||||
select tc.table_schema, tc.table_name, kc.column_name as primary_key
|
select tc.table_schema, tc.table_name, kc.column_name as primary_key
|
||||||
|
@ -168,6 +173,18 @@ module PostgresModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.client = this.pool
|
this.client = this.pool
|
||||||
|
this.setSchema()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
setSchema() {
|
||||||
|
if (!this.config.schema) {
|
||||||
|
this.config.schema = 'public'
|
||||||
|
}
|
||||||
|
this.client.on('connect', (client: any) => {
|
||||||
|
client.query(`SET search_path TO ${this.config.schema}`);
|
||||||
|
});
|
||||||
|
this.COLUMNS_SQL = `select * from information_schema.columns where table_schema = '${this.config.schema}'`
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue