@onivoro/server-typeorm-postgres 22.0.1 → 22.0.3

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.
@@ -15,12 +15,8 @@ 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;
23
18
  postOneWithoutReturn(entity: Partial<TEntity>): Promise<void>;
24
19
  postManyWithoutReturn(entities: Partial<TEntity>[]): Promise<void>;
25
20
  private throwNotImplemented;
21
+ protected mapPlaceholderExpression(length: number, index: number, column: string): string;
26
22
  }
@@ -83,33 +83,6 @@ 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
- }
113
86
  async postOneWithoutReturn(entity) {
114
87
  // PERFORM AN INSERT BUT NOT THE RETRIEVAL QUERY FOR PERFORMANCE
115
88
  const { insertQuery, values } = this.buildInsertQuery(entity);
@@ -123,6 +96,11 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
123
96
  throwNotImplemented(feature) {
124
97
  throw new common_1.NotImplementedException(`RedshiftRepository of type "${this.entityType?.name}" has no implementation for "${feature}"`);
125
98
  }
99
+ mapPlaceholderExpression(length, index, column) {
100
+ const exp = `$${length + index + 1}`;
101
+ const meta = this.columns[column];
102
+ return meta.type === 'jsonb' ? `JSON_PARSE(${exp})` : exp;
103
+ }
126
104
  };
127
105
  exports.RedshiftRepository = RedshiftRepository;
128
106
  exports.RedshiftRepository = RedshiftRepository = __decorate([
@@ -43,6 +43,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
43
43
  insertQuery: string;
44
44
  values: any[];
45
45
  };
46
+ protected mapPlaceholderExpression(length: number, index: number, column: string): string;
46
47
  protected buildSelectManyQuery(entities: Partial<TEntity>[]): {
47
48
  selectQuery: string;
48
49
  values: any[];
@@ -96,7 +96,7 @@ class TypeOrmRepository {
96
96
  const keys = Object.keys(entity);
97
97
  const values = Object.values(entity);
98
98
  const columnNames = keys.map(key => this.columns[key].databasePath).join(', ');
99
- const paramPlaceholders = keys.map((_, index) => `$${index + 1}`).join(', ');
99
+ const paramPlaceholders = keys.map((key, index) => this.mapPlaceholderExpression(0, index, key)).join(', ');
100
100
  const insertQuery = `INSERT INTO "${this.table}" (${columnNames}) VALUES (${paramPlaceholders})`;
101
101
  return { insertQuery, values };
102
102
  }
@@ -116,12 +116,17 @@ class TypeOrmRepository {
116
116
  Object.keys(keyMap).forEach(key => {
117
117
  values.push((typeof entity[key] === 'undefined') ? this.columns[key].default : entity[key]);
118
118
  });
119
- const paramPlaceholders = Object.keys(keyMap).map((_, index) => `$${length + index + 1}`).join(', ');
119
+ const paramPlaceholders = Object.keys(keyMap).map((_, index) => this.mapPlaceholderExpression(length, index, _)).join(', ');
120
120
  valuesExpressions.push(`(${paramPlaceholders})`);
121
121
  });
122
122
  const insertQuery = `INSERT INTO "${this.table}" (${columnNames}) VALUES ${valuesExpressions.join(', ')}`;
123
123
  return { insertQuery, values };
124
124
  }
125
+ mapPlaceholderExpression(length, index, column) {
126
+ const exp = `$${length + index + 1}`;
127
+ const meta = this.columns[column];
128
+ return meta.type === 'jsonb' ? exp : exp; // TODO: figure out how to handle this for postgres... $1::jsonb equivalent
129
+ }
125
130
  buildSelectManyQuery(entities) {
126
131
  const keyMap = {};
127
132
  entities.forEach(entity => {
@@ -15,12 +15,8 @@ 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;
23
18
  postOneWithoutReturn(entity: Partial<TEntity>): Promise<void>;
24
19
  postManyWithoutReturn(entities: Partial<TEntity>[]): Promise<void>;
25
20
  private throwNotImplemented;
21
+ protected mapPlaceholderExpression(length: number, index: number, column: string): string;
26
22
  }
@@ -83,33 +83,6 @@ 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
- }
113
86
  async postOneWithoutReturn(entity) {
114
87
  // PERFORM AN INSERT BUT NOT THE RETRIEVAL QUERY FOR PERFORMANCE
115
88
  const { insertQuery, values } = this.buildInsertQuery(entity);
@@ -123,6 +96,11 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
123
96
  throwNotImplemented(feature) {
124
97
  throw new common_1.NotImplementedException(`RedshiftRepository of type "${this.entityType?.name}" has no implementation for "${feature}"`);
125
98
  }
99
+ mapPlaceholderExpression(length, index, column) {
100
+ const exp = `$${length + index + 1}`;
101
+ const meta = this.columns[column];
102
+ return meta.type === 'jsonb' ? `JSON_PARSE(${exp})` : exp;
103
+ }
126
104
  };
127
105
  exports.RedshiftRepository = RedshiftRepository;
128
106
  exports.RedshiftRepository = RedshiftRepository = __decorate([
@@ -43,6 +43,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
43
43
  insertQuery: string;
44
44
  values: any[];
45
45
  };
46
+ protected mapPlaceholderExpression(length: number, index: number, column: string): string;
46
47
  protected buildSelectManyQuery(entities: Partial<TEntity>[]): {
47
48
  selectQuery: string;
48
49
  values: any[];
@@ -96,7 +96,7 @@ class TypeOrmRepository {
96
96
  const keys = Object.keys(entity);
97
97
  const values = Object.values(entity);
98
98
  const columnNames = keys.map(key => this.columns[key].databasePath).join(', ');
99
- const paramPlaceholders = keys.map((_, index) => `$${index + 1}`).join(', ');
99
+ const paramPlaceholders = keys.map((key, index) => this.mapPlaceholderExpression(0, index, key)).join(', ');
100
100
  const insertQuery = `INSERT INTO "${this.table}" (${columnNames}) VALUES (${paramPlaceholders})`;
101
101
  return { insertQuery, values };
102
102
  }
@@ -116,12 +116,17 @@ class TypeOrmRepository {
116
116
  Object.keys(keyMap).forEach(key => {
117
117
  values.push((typeof entity[key] === 'undefined') ? this.columns[key].default : entity[key]);
118
118
  });
119
- const paramPlaceholders = Object.keys(keyMap).map((_, index) => `$${length + index + 1}`).join(', ');
119
+ const paramPlaceholders = Object.keys(keyMap).map((_, index) => this.mapPlaceholderExpression(length, index, _)).join(', ');
120
120
  valuesExpressions.push(`(${paramPlaceholders})`);
121
121
  });
122
122
  const insertQuery = `INSERT INTO "${this.table}" (${columnNames}) VALUES ${valuesExpressions.join(', ')}`;
123
123
  return { insertQuery, values };
124
124
  }
125
+ mapPlaceholderExpression(length, index, column) {
126
+ const exp = `$${length + index + 1}`;
127
+ const meta = this.columns[column];
128
+ return meta.type === 'jsonb' ? exp : exp; // TODO: figure out how to handle this for postgres... $1::jsonb equivalent
129
+ }
125
130
  buildSelectManyQuery(entities) {
126
131
  const keyMap = {};
127
132
  entities.forEach(entity => {
@@ -15,12 +15,8 @@ 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;
23
18
  postOneWithoutReturn(entity: Partial<TEntity>): Promise<void>;
24
19
  postManyWithoutReturn(entities: Partial<TEntity>[]): Promise<void>;
25
20
  private throwNotImplemented;
21
+ protected mapPlaceholderExpression(length: number, index: number, column: string): string;
26
22
  }
@@ -43,6 +43,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
43
43
  insertQuery: string;
44
44
  values: any[];
45
45
  };
46
+ protected mapPlaceholderExpression(length: number, index: number, column: string): string;
46
47
  protected buildSelectManyQuery(entities: Partial<TEntity>[]): {
47
48
  selectQuery: string;
48
49
  values: any[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/server-typeorm-postgres",
3
- "version": "22.0.1",
3
+ "version": "22.0.3",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/onivoro/server-typeorm-postgres.git"
6
6
  },