@onivoro/server-typeorm-postgres 22.0.0 → 22.0.1
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.d.ts +5 -0
- package/dist/cjs/lib/classes/redshift-repository.class.js +30 -3
- package/dist/esm/lib/classes/redshift-repository.class.d.ts +5 -0
- package/dist/esm/lib/classes/redshift-repository.class.js +30 -3
- package/dist/types/lib/classes/redshift-repository.class.d.ts +5 -0
- package/package.json +1 -1
|
@@ -15,6 +15,11 @@ export declare class RedshiftRepository<TEntity> extends TypeOrmRepository<TEnti
|
|
|
15
15
|
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
16
16
|
getManyAndCount(options: FindManyOptions<TEntity>): Promise<[TEntity[], number]>;
|
|
17
17
|
softDelete(where: FindOptionsWhere<TEntity>): Promise<void>;
|
|
18
|
+
protected buildInsertManyQuery(entities: Partial<TEntity>[]): {
|
|
19
|
+
insertQuery: string;
|
|
20
|
+
values: any[];
|
|
21
|
+
};
|
|
22
|
+
private mapPlaceholderExpression;
|
|
18
23
|
postOneWithoutReturn(entity: Partial<TEntity>): Promise<void>;
|
|
19
24
|
postManyWithoutReturn(entities: Partial<TEntity>[]): Promise<void>;
|
|
20
25
|
private throwNotImplemented;
|
|
@@ -42,10 +42,10 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
|
|
|
42
42
|
Object.entries(where).forEach(([propertyPath, value], index) => {
|
|
43
43
|
const key = this.columns[propertyPath].databasePath;
|
|
44
44
|
if (index === 0) {
|
|
45
|
-
whereClause += ` WHERE ${key} =
|
|
45
|
+
whereClause += ` WHERE ${key} = ${this.mapPlaceholderExpression(0, index, propertyPath)}`;
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
|
-
whereClause += ` AND ${key} =
|
|
48
|
+
whereClause += ` AND ${key} = ${this.mapPlaceholderExpression(0, index, propertyPath)}`;
|
|
49
49
|
}
|
|
50
50
|
queryParams.push(value);
|
|
51
51
|
});
|
|
@@ -53,7 +53,7 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
|
|
|
53
53
|
let setExpressions = [];
|
|
54
54
|
const length = queryParams?.length;
|
|
55
55
|
Object.entries(body).forEach(([key, value], index) => {
|
|
56
|
-
setExpressions.push(`${this.columns[key].databasePath} =
|
|
56
|
+
setExpressions.push(`${this.columns[key].databasePath} = ${this.mapPlaceholderExpression(length, index, key)}`);
|
|
57
57
|
setParams.push(value);
|
|
58
58
|
});
|
|
59
59
|
let query = `UPDATE "${this.table}" SET ${setExpressions.join(', ')} ${whereClause}`;
|
|
@@ -83,6 +83,33 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
|
|
|
83
83
|
async softDelete(where) {
|
|
84
84
|
await this.patch(where, { deletedAt: new Date().toISOString() });
|
|
85
85
|
}
|
|
86
|
+
buildInsertManyQuery(entities) {
|
|
87
|
+
const keyMap = {};
|
|
88
|
+
entities.forEach(entity => {
|
|
89
|
+
Object.keys(entity)
|
|
90
|
+
.forEach(key => {
|
|
91
|
+
keyMap[key] = true;
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
const columnNames = Object.keys(keyMap).map(key => this.columns[key].databasePath).join(', ');
|
|
95
|
+
const valuesExpressions = [];
|
|
96
|
+
const values = [];
|
|
97
|
+
entities.forEach(entity => {
|
|
98
|
+
const length = values.length;
|
|
99
|
+
Object.keys(keyMap).forEach(key => {
|
|
100
|
+
values.push((typeof entity[key] === 'undefined') ? this.columns[key].default : entity[key]);
|
|
101
|
+
});
|
|
102
|
+
const paramPlaceholders = Object.keys(keyMap).map((_, index) => this.mapPlaceholderExpression(length, index, _)).join(', ');
|
|
103
|
+
valuesExpressions.push(`(${paramPlaceholders})`);
|
|
104
|
+
});
|
|
105
|
+
const insertQuery = `INSERT INTO "${this.table}" (${columnNames}) VALUES ${valuesExpressions.join(', ')}`;
|
|
106
|
+
return { insertQuery, values };
|
|
107
|
+
}
|
|
108
|
+
mapPlaceholderExpression(length, index, column) {
|
|
109
|
+
const exp = `$${length + index + 1}`;
|
|
110
|
+
const meta = this.columns[column];
|
|
111
|
+
return meta.type === 'jsonb' ? `JSON_PARSE('${exp}')` : exp;
|
|
112
|
+
}
|
|
86
113
|
async postOneWithoutReturn(entity) {
|
|
87
114
|
// PERFORM AN INSERT BUT NOT THE RETRIEVAL QUERY FOR PERFORMANCE
|
|
88
115
|
const { insertQuery, values } = this.buildInsertQuery(entity);
|
|
@@ -15,6 +15,11 @@ export declare class RedshiftRepository<TEntity> extends TypeOrmRepository<TEnti
|
|
|
15
15
|
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
16
16
|
getManyAndCount(options: FindManyOptions<TEntity>): Promise<[TEntity[], number]>;
|
|
17
17
|
softDelete(where: FindOptionsWhere<TEntity>): Promise<void>;
|
|
18
|
+
protected buildInsertManyQuery(entities: Partial<TEntity>[]): {
|
|
19
|
+
insertQuery: string;
|
|
20
|
+
values: any[];
|
|
21
|
+
};
|
|
22
|
+
private mapPlaceholderExpression;
|
|
18
23
|
postOneWithoutReturn(entity: Partial<TEntity>): Promise<void>;
|
|
19
24
|
postManyWithoutReturn(entities: Partial<TEntity>[]): Promise<void>;
|
|
20
25
|
private throwNotImplemented;
|
|
@@ -42,10 +42,10 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
|
|
|
42
42
|
Object.entries(where).forEach(([propertyPath, value], index) => {
|
|
43
43
|
const key = this.columns[propertyPath].databasePath;
|
|
44
44
|
if (index === 0) {
|
|
45
|
-
whereClause += ` WHERE ${key} =
|
|
45
|
+
whereClause += ` WHERE ${key} = ${this.mapPlaceholderExpression(0, index, propertyPath)}`;
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
|
-
whereClause += ` AND ${key} =
|
|
48
|
+
whereClause += ` AND ${key} = ${this.mapPlaceholderExpression(0, index, propertyPath)}`;
|
|
49
49
|
}
|
|
50
50
|
queryParams.push(value);
|
|
51
51
|
});
|
|
@@ -53,7 +53,7 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
|
|
|
53
53
|
let setExpressions = [];
|
|
54
54
|
const length = queryParams?.length;
|
|
55
55
|
Object.entries(body).forEach(([key, value], index) => {
|
|
56
|
-
setExpressions.push(`${this.columns[key].databasePath} =
|
|
56
|
+
setExpressions.push(`${this.columns[key].databasePath} = ${this.mapPlaceholderExpression(length, index, key)}`);
|
|
57
57
|
setParams.push(value);
|
|
58
58
|
});
|
|
59
59
|
let query = `UPDATE "${this.table}" SET ${setExpressions.join(', ')} ${whereClause}`;
|
|
@@ -83,6 +83,33 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
|
|
|
83
83
|
async softDelete(where) {
|
|
84
84
|
await this.patch(where, { deletedAt: new Date().toISOString() });
|
|
85
85
|
}
|
|
86
|
+
buildInsertManyQuery(entities) {
|
|
87
|
+
const keyMap = {};
|
|
88
|
+
entities.forEach(entity => {
|
|
89
|
+
Object.keys(entity)
|
|
90
|
+
.forEach(key => {
|
|
91
|
+
keyMap[key] = true;
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
const columnNames = Object.keys(keyMap).map(key => this.columns[key].databasePath).join(', ');
|
|
95
|
+
const valuesExpressions = [];
|
|
96
|
+
const values = [];
|
|
97
|
+
entities.forEach(entity => {
|
|
98
|
+
const length = values.length;
|
|
99
|
+
Object.keys(keyMap).forEach(key => {
|
|
100
|
+
values.push((typeof entity[key] === 'undefined') ? this.columns[key].default : entity[key]);
|
|
101
|
+
});
|
|
102
|
+
const paramPlaceholders = Object.keys(keyMap).map((_, index) => this.mapPlaceholderExpression(length, index, _)).join(', ');
|
|
103
|
+
valuesExpressions.push(`(${paramPlaceholders})`);
|
|
104
|
+
});
|
|
105
|
+
const insertQuery = `INSERT INTO "${this.table}" (${columnNames}) VALUES ${valuesExpressions.join(', ')}`;
|
|
106
|
+
return { insertQuery, values };
|
|
107
|
+
}
|
|
108
|
+
mapPlaceholderExpression(length, index, column) {
|
|
109
|
+
const exp = `$${length + index + 1}`;
|
|
110
|
+
const meta = this.columns[column];
|
|
111
|
+
return meta.type === 'jsonb' ? `JSON_PARSE('${exp}')` : exp;
|
|
112
|
+
}
|
|
86
113
|
async postOneWithoutReturn(entity) {
|
|
87
114
|
// PERFORM AN INSERT BUT NOT THE RETRIEVAL QUERY FOR PERFORMANCE
|
|
88
115
|
const { insertQuery, values } = this.buildInsertQuery(entity);
|
|
@@ -15,6 +15,11 @@ export declare class RedshiftRepository<TEntity> extends TypeOrmRepository<TEnti
|
|
|
15
15
|
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
16
16
|
getManyAndCount(options: FindManyOptions<TEntity>): Promise<[TEntity[], number]>;
|
|
17
17
|
softDelete(where: FindOptionsWhere<TEntity>): Promise<void>;
|
|
18
|
+
protected buildInsertManyQuery(entities: Partial<TEntity>[]): {
|
|
19
|
+
insertQuery: string;
|
|
20
|
+
values: any[];
|
|
21
|
+
};
|
|
22
|
+
private mapPlaceholderExpression;
|
|
18
23
|
postOneWithoutReturn(entity: Partial<TEntity>): Promise<void>;
|
|
19
24
|
postManyWithoutReturn(entities: Partial<TEntity>[]): Promise<void>;
|
|
20
25
|
private throwNotImplemented;
|