@onivoro/server-typeorm-postgres 22.0.3 → 22.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/lib/classes/redshift-repository.class.js +1 -1
- package/dist/cjs/lib/classes/type-orm-repository.class.d.ts +3 -0
- package/dist/cjs/lib/classes/type-orm-repository.class.js +17 -8
- package/dist/cjs/lib/functions/data-source-config-factory.function.js +2 -1
- package/dist/cjs/lib/types/data-source-options.interface.d.ts +1 -0
- package/dist/esm/lib/classes/redshift-repository.class.js +1 -1
- package/dist/esm/lib/classes/type-orm-repository.class.d.ts +3 -0
- package/dist/esm/lib/classes/type-orm-repository.class.js +17 -8
- package/dist/esm/lib/functions/data-source-config-factory.function.js +2 -1
- package/dist/esm/lib/types/data-source-options.interface.d.ts +1 -0
- package/dist/types/lib/classes/type-orm-repository.class.d.ts +3 -0
- package/dist/types/lib/types/data-source-options.interface.d.ts +1 -0
- package/package.json +1 -1
|
@@ -56,7 +56,7 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
|
|
|
56
56
|
setExpressions.push(`${this.columns[key].databasePath} = ${this.mapPlaceholderExpression(length, index, key)}`);
|
|
57
57
|
setParams.push(value);
|
|
58
58
|
});
|
|
59
|
-
let query = `UPDATE
|
|
59
|
+
let query = `UPDATE ${this.getTableNameExpression()} SET ${setExpressions.join(', ')} ${whereClause}`;
|
|
60
60
|
await this.query(query, [...queryParams, ...setParams]);
|
|
61
61
|
}
|
|
62
62
|
async postOne(entity) {
|
|
@@ -8,6 +8,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
|
|
|
8
8
|
entityManager: EntityManager;
|
|
9
9
|
protected columns: TKeysOf<TEntity, TTableMeta>;
|
|
10
10
|
protected table: string;
|
|
11
|
+
protected schema: string;
|
|
11
12
|
debug: boolean;
|
|
12
13
|
constructor(entityType: any, entityManager: EntityManager);
|
|
13
14
|
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
@@ -23,6 +24,8 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
|
|
|
23
24
|
get repo(): import("typeorm").Repository<import("typeorm").ObjectLiteral>;
|
|
24
25
|
protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
|
|
25
26
|
protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
|
|
27
|
+
protected getSchemaPrefix(): string;
|
|
28
|
+
protected getTableNameExpression(): string;
|
|
26
29
|
protected buildSelectStatement(options: FindManyOptions<TEntity>): {
|
|
27
30
|
query: string;
|
|
28
31
|
queryParams: any[];
|
|
@@ -6,12 +6,14 @@ class TypeOrmRepository {
|
|
|
6
6
|
entityManager;
|
|
7
7
|
columns = {};
|
|
8
8
|
table;
|
|
9
|
+
schema;
|
|
9
10
|
debug = false;
|
|
10
11
|
constructor(entityType, entityManager) {
|
|
11
12
|
this.entityType = entityType;
|
|
12
13
|
this.entityManager = entityManager;
|
|
13
|
-
const { tableName } = this.repo.metadata;
|
|
14
|
+
const { tableName, schema } = this.repo.metadata;
|
|
14
15
|
this.table = tableName;
|
|
16
|
+
this.schema = schema;
|
|
15
17
|
this.repo.metadata.columns.forEach((_) => {
|
|
16
18
|
const { databasePath, propertyPath, type, isPrimary } = _;
|
|
17
19
|
this.columns[propertyPath] = { databasePath, type, propertyPath, isPrimary, default: _.default };
|
|
@@ -67,14 +69,21 @@ class TypeOrmRepository {
|
|
|
67
69
|
const insertedEntity = insertionResult.generatedMaps;
|
|
68
70
|
return insertedEntity;
|
|
69
71
|
}
|
|
72
|
+
getSchemaPrefix() {
|
|
73
|
+
return this.schema ? `"${this.schema}".` : '';
|
|
74
|
+
}
|
|
75
|
+
getTableNameExpression() {
|
|
76
|
+
const schemaPrefix = this.getSchemaPrefix();
|
|
77
|
+
return `${schemaPrefix}"${this.table}"`;
|
|
78
|
+
}
|
|
70
79
|
buildSelectStatement(options) {
|
|
71
80
|
const { whereClause, queryParams } = this.buildWhereExpression(options.where);
|
|
72
|
-
const query = `SELECT * FROM
|
|
81
|
+
const query = `SELECT * FROM ${this.getTableNameExpression()}${whereClause};`;
|
|
73
82
|
return { query, queryParams };
|
|
74
83
|
}
|
|
75
84
|
buildDeleteStatement(where) {
|
|
76
85
|
const { whereClause, queryParams } = this.buildWhereExpression(where);
|
|
77
|
-
const query = `DELETE FROM
|
|
86
|
+
const query = `DELETE FROM ${this.getTableNameExpression()}${whereClause};`;
|
|
78
87
|
return { query, queryParams };
|
|
79
88
|
}
|
|
80
89
|
buildWhereExpression(where) {
|
|
@@ -97,7 +106,7 @@ class TypeOrmRepository {
|
|
|
97
106
|
const values = Object.values(entity);
|
|
98
107
|
const columnNames = keys.map(key => this.columns[key].databasePath).join(', ');
|
|
99
108
|
const paramPlaceholders = keys.map((key, index) => this.mapPlaceholderExpression(0, index, key)).join(', ');
|
|
100
|
-
const insertQuery = `INSERT INTO
|
|
109
|
+
const insertQuery = `INSERT INTO ${this.getTableNameExpression()} (${columnNames}) VALUES (${paramPlaceholders})`;
|
|
101
110
|
return { insertQuery, values };
|
|
102
111
|
}
|
|
103
112
|
buildInsertManyQuery(entities) {
|
|
@@ -119,7 +128,7 @@ class TypeOrmRepository {
|
|
|
119
128
|
const paramPlaceholders = Object.keys(keyMap).map((_, index) => this.mapPlaceholderExpression(length, index, _)).join(', ');
|
|
120
129
|
valuesExpressions.push(`(${paramPlaceholders})`);
|
|
121
130
|
});
|
|
122
|
-
const insertQuery = `INSERT INTO
|
|
131
|
+
const insertQuery = `INSERT INTO ${this.getTableNameExpression()} (${columnNames}) VALUES ${valuesExpressions.join(', ')}`;
|
|
123
132
|
return { insertQuery, values };
|
|
124
133
|
}
|
|
125
134
|
mapPlaceholderExpression(length, index, column) {
|
|
@@ -143,7 +152,7 @@ class TypeOrmRepository {
|
|
|
143
152
|
values.push((typeof entity[key] === 'undefined') ? this.columns[key].default : entity[key]);
|
|
144
153
|
});
|
|
145
154
|
const whereExpression = Object.keys(keyMap).map((_, index) => `(${this.columns[_].databasePath} = $${length + index + 1})`).join(' AND ');
|
|
146
|
-
selectExpressions.push(`(select * from
|
|
155
|
+
selectExpressions.push(`(select * from ${this.getTableNameExpression()} where (${whereExpression}))`);
|
|
147
156
|
});
|
|
148
157
|
const selectQuery = selectExpressions.join(' UNION ');
|
|
149
158
|
return { selectQuery, values };
|
|
@@ -158,11 +167,11 @@ class TypeOrmRepository {
|
|
|
158
167
|
}
|
|
159
168
|
async query(query, parameters) {
|
|
160
169
|
if (this.debug) {
|
|
161
|
-
console.log({ table: this.table, query, parameters });
|
|
170
|
+
console.log({ schema: this.schema, table: this.table, query, parameters });
|
|
162
171
|
}
|
|
163
172
|
const result = await this.repo.query(query, parameters);
|
|
164
173
|
if (this.debug) {
|
|
165
|
-
console.log({ table: this.table, query, parameters, result });
|
|
174
|
+
console.log({ schema: this.schema, table: this.table, query, parameters, result });
|
|
166
175
|
}
|
|
167
176
|
return result;
|
|
168
177
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.dataSourceConfigFactory = dataSourceConfigFactory;
|
|
4
4
|
const typeorm_naming_strategies_1 = require("typeorm-naming-strategies");
|
|
5
5
|
function dataSourceConfigFactory(name, options, entities) {
|
|
6
|
-
const { ca, database, host, password, port, username, synchronize = false, logging = false } = options;
|
|
6
|
+
const { ca, database, host, password, port, username, synchronize = false, logging = false, schema, } = options;
|
|
7
7
|
const config = {
|
|
8
8
|
name,
|
|
9
9
|
type: 'postgres',
|
|
@@ -16,6 +16,7 @@ function dataSourceConfigFactory(name, options, entities) {
|
|
|
16
16
|
synchronize,
|
|
17
17
|
logging,
|
|
18
18
|
entities,
|
|
19
|
+
schema,
|
|
19
20
|
subscribers: [],
|
|
20
21
|
migrations: [],
|
|
21
22
|
namingStrategy: new typeorm_naming_strategies_1.SnakeNamingStrategy(),
|
|
@@ -56,7 +56,7 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
|
|
|
56
56
|
setExpressions.push(`${this.columns[key].databasePath} = ${this.mapPlaceholderExpression(length, index, key)}`);
|
|
57
57
|
setParams.push(value);
|
|
58
58
|
});
|
|
59
|
-
let query = `UPDATE
|
|
59
|
+
let query = `UPDATE ${this.getTableNameExpression()} SET ${setExpressions.join(', ')} ${whereClause}`;
|
|
60
60
|
await this.query(query, [...queryParams, ...setParams]);
|
|
61
61
|
}
|
|
62
62
|
async postOne(entity) {
|
|
@@ -8,6 +8,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
|
|
|
8
8
|
entityManager: EntityManager;
|
|
9
9
|
protected columns: TKeysOf<TEntity, TTableMeta>;
|
|
10
10
|
protected table: string;
|
|
11
|
+
protected schema: string;
|
|
11
12
|
debug: boolean;
|
|
12
13
|
constructor(entityType: any, entityManager: EntityManager);
|
|
13
14
|
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
@@ -23,6 +24,8 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
|
|
|
23
24
|
get repo(): import("typeorm").Repository<import("typeorm").ObjectLiteral>;
|
|
24
25
|
protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
|
|
25
26
|
protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
|
|
27
|
+
protected getSchemaPrefix(): string;
|
|
28
|
+
protected getTableNameExpression(): string;
|
|
26
29
|
protected buildSelectStatement(options: FindManyOptions<TEntity>): {
|
|
27
30
|
query: string;
|
|
28
31
|
queryParams: any[];
|
|
@@ -6,12 +6,14 @@ class TypeOrmRepository {
|
|
|
6
6
|
entityManager;
|
|
7
7
|
columns = {};
|
|
8
8
|
table;
|
|
9
|
+
schema;
|
|
9
10
|
debug = false;
|
|
10
11
|
constructor(entityType, entityManager) {
|
|
11
12
|
this.entityType = entityType;
|
|
12
13
|
this.entityManager = entityManager;
|
|
13
|
-
const { tableName } = this.repo.metadata;
|
|
14
|
+
const { tableName, schema } = this.repo.metadata;
|
|
14
15
|
this.table = tableName;
|
|
16
|
+
this.schema = schema;
|
|
15
17
|
this.repo.metadata.columns.forEach((_) => {
|
|
16
18
|
const { databasePath, propertyPath, type, isPrimary } = _;
|
|
17
19
|
this.columns[propertyPath] = { databasePath, type, propertyPath, isPrimary, default: _.default };
|
|
@@ -67,14 +69,21 @@ class TypeOrmRepository {
|
|
|
67
69
|
const insertedEntity = insertionResult.generatedMaps;
|
|
68
70
|
return insertedEntity;
|
|
69
71
|
}
|
|
72
|
+
getSchemaPrefix() {
|
|
73
|
+
return this.schema ? `"${this.schema}".` : '';
|
|
74
|
+
}
|
|
75
|
+
getTableNameExpression() {
|
|
76
|
+
const schemaPrefix = this.getSchemaPrefix();
|
|
77
|
+
return `${schemaPrefix}"${this.table}"`;
|
|
78
|
+
}
|
|
70
79
|
buildSelectStatement(options) {
|
|
71
80
|
const { whereClause, queryParams } = this.buildWhereExpression(options.where);
|
|
72
|
-
const query = `SELECT * FROM
|
|
81
|
+
const query = `SELECT * FROM ${this.getTableNameExpression()}${whereClause};`;
|
|
73
82
|
return { query, queryParams };
|
|
74
83
|
}
|
|
75
84
|
buildDeleteStatement(where) {
|
|
76
85
|
const { whereClause, queryParams } = this.buildWhereExpression(where);
|
|
77
|
-
const query = `DELETE FROM
|
|
86
|
+
const query = `DELETE FROM ${this.getTableNameExpression()}${whereClause};`;
|
|
78
87
|
return { query, queryParams };
|
|
79
88
|
}
|
|
80
89
|
buildWhereExpression(where) {
|
|
@@ -97,7 +106,7 @@ class TypeOrmRepository {
|
|
|
97
106
|
const values = Object.values(entity);
|
|
98
107
|
const columnNames = keys.map(key => this.columns[key].databasePath).join(', ');
|
|
99
108
|
const paramPlaceholders = keys.map((key, index) => this.mapPlaceholderExpression(0, index, key)).join(', ');
|
|
100
|
-
const insertQuery = `INSERT INTO
|
|
109
|
+
const insertQuery = `INSERT INTO ${this.getTableNameExpression()} (${columnNames}) VALUES (${paramPlaceholders})`;
|
|
101
110
|
return { insertQuery, values };
|
|
102
111
|
}
|
|
103
112
|
buildInsertManyQuery(entities) {
|
|
@@ -119,7 +128,7 @@ class TypeOrmRepository {
|
|
|
119
128
|
const paramPlaceholders = Object.keys(keyMap).map((_, index) => this.mapPlaceholderExpression(length, index, _)).join(', ');
|
|
120
129
|
valuesExpressions.push(`(${paramPlaceholders})`);
|
|
121
130
|
});
|
|
122
|
-
const insertQuery = `INSERT INTO
|
|
131
|
+
const insertQuery = `INSERT INTO ${this.getTableNameExpression()} (${columnNames}) VALUES ${valuesExpressions.join(', ')}`;
|
|
123
132
|
return { insertQuery, values };
|
|
124
133
|
}
|
|
125
134
|
mapPlaceholderExpression(length, index, column) {
|
|
@@ -143,7 +152,7 @@ class TypeOrmRepository {
|
|
|
143
152
|
values.push((typeof entity[key] === 'undefined') ? this.columns[key].default : entity[key]);
|
|
144
153
|
});
|
|
145
154
|
const whereExpression = Object.keys(keyMap).map((_, index) => `(${this.columns[_].databasePath} = $${length + index + 1})`).join(' AND ');
|
|
146
|
-
selectExpressions.push(`(select * from
|
|
155
|
+
selectExpressions.push(`(select * from ${this.getTableNameExpression()} where (${whereExpression}))`);
|
|
147
156
|
});
|
|
148
157
|
const selectQuery = selectExpressions.join(' UNION ');
|
|
149
158
|
return { selectQuery, values };
|
|
@@ -158,11 +167,11 @@ class TypeOrmRepository {
|
|
|
158
167
|
}
|
|
159
168
|
async query(query, parameters) {
|
|
160
169
|
if (this.debug) {
|
|
161
|
-
console.log({ table: this.table, query, parameters });
|
|
170
|
+
console.log({ schema: this.schema, table: this.table, query, parameters });
|
|
162
171
|
}
|
|
163
172
|
const result = await this.repo.query(query, parameters);
|
|
164
173
|
if (this.debug) {
|
|
165
|
-
console.log({ table: this.table, query, parameters, result });
|
|
174
|
+
console.log({ schema: this.schema, table: this.table, query, parameters, result });
|
|
166
175
|
}
|
|
167
176
|
return result;
|
|
168
177
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.dataSourceConfigFactory = dataSourceConfigFactory;
|
|
4
4
|
const typeorm_naming_strategies_1 = require("typeorm-naming-strategies");
|
|
5
5
|
function dataSourceConfigFactory(name, options, entities) {
|
|
6
|
-
const { ca, database, host, password, port, username, synchronize = false, logging = false } = options;
|
|
6
|
+
const { ca, database, host, password, port, username, synchronize = false, logging = false, schema, } = options;
|
|
7
7
|
const config = {
|
|
8
8
|
name,
|
|
9
9
|
type: 'postgres',
|
|
@@ -16,6 +16,7 @@ function dataSourceConfigFactory(name, options, entities) {
|
|
|
16
16
|
synchronize,
|
|
17
17
|
logging,
|
|
18
18
|
entities,
|
|
19
|
+
schema,
|
|
19
20
|
subscribers: [],
|
|
20
21
|
migrations: [],
|
|
21
22
|
namingStrategy: new typeorm_naming_strategies_1.SnakeNamingStrategy(),
|
|
@@ -8,6 +8,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
|
|
|
8
8
|
entityManager: EntityManager;
|
|
9
9
|
protected columns: TKeysOf<TEntity, TTableMeta>;
|
|
10
10
|
protected table: string;
|
|
11
|
+
protected schema: string;
|
|
11
12
|
debug: boolean;
|
|
12
13
|
constructor(entityType: any, entityManager: EntityManager);
|
|
13
14
|
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
@@ -23,6 +24,8 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
|
|
|
23
24
|
get repo(): import("typeorm").Repository<import("typeorm").ObjectLiteral>;
|
|
24
25
|
protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
|
|
25
26
|
protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
|
|
27
|
+
protected getSchemaPrefix(): string;
|
|
28
|
+
protected getTableNameExpression(): string;
|
|
26
29
|
protected buildSelectStatement(options: FindManyOptions<TEntity>): {
|
|
27
30
|
query: string;
|
|
28
31
|
queryParams: any[];
|