@onivoro/server-typeorm-postgres 22.0.8 → 22.0.10
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 +7 -4
- package/dist/cjs/lib/classes/type-orm-repository.class.d.ts +5 -5
- package/dist/cjs/lib/classes/type-orm-repository.class.js +18 -8
- package/dist/esm/lib/classes/redshift-repository.class.js +7 -4
- package/dist/esm/lib/classes/type-orm-repository.class.d.ts +5 -5
- package/dist/esm/lib/classes/type-orm-repository.class.js +18 -8
- package/dist/types/lib/classes/type-orm-repository.class.d.ts +5 -5
- package/package.json +1 -1
|
@@ -64,10 +64,13 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
|
|
|
64
64
|
return await this.getOne({ where: entity });
|
|
65
65
|
}
|
|
66
66
|
async postMany(entities) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
if (entities?.length) {
|
|
68
|
+
const { insertQuery, values } = this.buildInsertManyQuery(entities);
|
|
69
|
+
await this.query(insertQuery, values);
|
|
70
|
+
const { selectQuery, values: selectValues } = this.buildSelectManyQuery(entities);
|
|
71
|
+
return await this.queryAndMap(selectQuery, selectValues);
|
|
72
|
+
}
|
|
73
|
+
return [];
|
|
71
74
|
}
|
|
72
75
|
async put(options, body) {
|
|
73
76
|
this.throwNotImplemented('put');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
|
|
1
|
+
import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, ObjectLiteral, Repository } from 'typeorm';
|
|
2
2
|
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
|
|
3
3
|
import { IEntityProvider } from '../types/entity-provider.interface';
|
|
4
4
|
import { TKeysOf } from '@onivoro/isomorphic-common';
|
|
@@ -6,9 +6,9 @@ import { TTableMeta } from '../types/table-meta.type';
|
|
|
6
6
|
export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEntity, FindOneOptions<TEntity>, FindManyOptions<TEntity>, FindOptionsWhere<TEntity>, QueryDeepPartialEntity<TEntity>> {
|
|
7
7
|
entityType: any;
|
|
8
8
|
entityManager: EntityManager;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
columns: TKeysOf<TEntity, TTableMeta>;
|
|
10
|
+
table: string;
|
|
11
|
+
schema: string;
|
|
12
12
|
debug: boolean;
|
|
13
13
|
constructor(entityType: any, entityManager: EntityManager);
|
|
14
14
|
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
@@ -21,7 +21,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
|
|
|
21
21
|
softDelete(options: FindOptionsWhere<TEntity>): Promise<void>;
|
|
22
22
|
put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
23
23
|
patch(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
24
|
-
get repo():
|
|
24
|
+
get repo(): Repository<ObjectLiteral>;
|
|
25
25
|
protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
|
|
26
26
|
protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
|
|
27
27
|
protected getSchemaPrefix(): string;
|
|
@@ -11,13 +11,17 @@ class TypeOrmRepository {
|
|
|
11
11
|
constructor(entityType, entityManager) {
|
|
12
12
|
this.entityType = entityType;
|
|
13
13
|
this.entityManager = entityManager;
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
|
|
14
|
+
this.table = '';
|
|
15
|
+
this.schema = '';
|
|
16
|
+
if (this.repo?.metadata?.columns?.length) {
|
|
17
|
+
const { tableName, schema } = this.repo.metadata;
|
|
18
|
+
this.table = tableName;
|
|
19
|
+
this.schema = schema;
|
|
20
|
+
this.repo.metadata.columns.forEach((_) => {
|
|
21
|
+
const { databasePath, propertyPath, type, isPrimary } = _;
|
|
22
|
+
this.columns[propertyPath] = { databasePath, type, propertyPath, isPrimary, default: _.default };
|
|
23
|
+
});
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
forTransaction(entityManager) {
|
|
23
27
|
return new this.constructor(this.entityType, entityManager);
|
|
@@ -54,7 +58,13 @@ class TypeOrmRepository {
|
|
|
54
58
|
await this.repo.update(options, body);
|
|
55
59
|
}
|
|
56
60
|
get repo() {
|
|
57
|
-
|
|
61
|
+
try {
|
|
62
|
+
return this.entityManager.getRepository(this.entityType);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error(`EntityManager.getRepository failed. Falling back to EntityManager for basic functionality.`);
|
|
66
|
+
return this.entityManager;
|
|
67
|
+
}
|
|
58
68
|
}
|
|
59
69
|
async insertAndReturn(entityToInsert) {
|
|
60
70
|
return (await this.insertAndReturnMany([entityToInsert]))[0];
|
|
@@ -64,10 +64,13 @@ let RedshiftRepository = class RedshiftRepository extends type_orm_repository_cl
|
|
|
64
64
|
return await this.getOne({ where: entity });
|
|
65
65
|
}
|
|
66
66
|
async postMany(entities) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
if (entities?.length) {
|
|
68
|
+
const { insertQuery, values } = this.buildInsertManyQuery(entities);
|
|
69
|
+
await this.query(insertQuery, values);
|
|
70
|
+
const { selectQuery, values: selectValues } = this.buildSelectManyQuery(entities);
|
|
71
|
+
return await this.queryAndMap(selectQuery, selectValues);
|
|
72
|
+
}
|
|
73
|
+
return [];
|
|
71
74
|
}
|
|
72
75
|
async put(options, body) {
|
|
73
76
|
this.throwNotImplemented('put');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
|
|
1
|
+
import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, ObjectLiteral, Repository } from 'typeorm';
|
|
2
2
|
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
|
|
3
3
|
import { IEntityProvider } from '../types/entity-provider.interface';
|
|
4
4
|
import { TKeysOf } from '@onivoro/isomorphic-common';
|
|
@@ -6,9 +6,9 @@ import { TTableMeta } from '../types/table-meta.type';
|
|
|
6
6
|
export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEntity, FindOneOptions<TEntity>, FindManyOptions<TEntity>, FindOptionsWhere<TEntity>, QueryDeepPartialEntity<TEntity>> {
|
|
7
7
|
entityType: any;
|
|
8
8
|
entityManager: EntityManager;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
columns: TKeysOf<TEntity, TTableMeta>;
|
|
10
|
+
table: string;
|
|
11
|
+
schema: string;
|
|
12
12
|
debug: boolean;
|
|
13
13
|
constructor(entityType: any, entityManager: EntityManager);
|
|
14
14
|
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
@@ -21,7 +21,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
|
|
|
21
21
|
softDelete(options: FindOptionsWhere<TEntity>): Promise<void>;
|
|
22
22
|
put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
23
23
|
patch(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
24
|
-
get repo():
|
|
24
|
+
get repo(): Repository<ObjectLiteral>;
|
|
25
25
|
protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
|
|
26
26
|
protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
|
|
27
27
|
protected getSchemaPrefix(): string;
|
|
@@ -11,13 +11,17 @@ class TypeOrmRepository {
|
|
|
11
11
|
constructor(entityType, entityManager) {
|
|
12
12
|
this.entityType = entityType;
|
|
13
13
|
this.entityManager = entityManager;
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
|
|
14
|
+
this.table = '';
|
|
15
|
+
this.schema = '';
|
|
16
|
+
if (this.repo?.metadata?.columns?.length) {
|
|
17
|
+
const { tableName, schema } = this.repo.metadata;
|
|
18
|
+
this.table = tableName;
|
|
19
|
+
this.schema = schema;
|
|
20
|
+
this.repo.metadata.columns.forEach((_) => {
|
|
21
|
+
const { databasePath, propertyPath, type, isPrimary } = _;
|
|
22
|
+
this.columns[propertyPath] = { databasePath, type, propertyPath, isPrimary, default: _.default };
|
|
23
|
+
});
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
forTransaction(entityManager) {
|
|
23
27
|
return new this.constructor(this.entityType, entityManager);
|
|
@@ -54,7 +58,13 @@ class TypeOrmRepository {
|
|
|
54
58
|
await this.repo.update(options, body);
|
|
55
59
|
}
|
|
56
60
|
get repo() {
|
|
57
|
-
|
|
61
|
+
try {
|
|
62
|
+
return this.entityManager.getRepository(this.entityType);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error(`EntityManager.getRepository failed. Falling back to EntityManager for basic functionality.`);
|
|
66
|
+
return this.entityManager;
|
|
67
|
+
}
|
|
58
68
|
}
|
|
59
69
|
async insertAndReturn(entityToInsert) {
|
|
60
70
|
return (await this.insertAndReturnMany([entityToInsert]))[0];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
|
|
1
|
+
import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, ObjectLiteral, Repository } from 'typeorm';
|
|
2
2
|
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
|
|
3
3
|
import { IEntityProvider } from '../types/entity-provider.interface';
|
|
4
4
|
import { TKeysOf } from '@onivoro/isomorphic-common';
|
|
@@ -6,9 +6,9 @@ import { TTableMeta } from '../types/table-meta.type';
|
|
|
6
6
|
export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEntity, FindOneOptions<TEntity>, FindManyOptions<TEntity>, FindOptionsWhere<TEntity>, QueryDeepPartialEntity<TEntity>> {
|
|
7
7
|
entityType: any;
|
|
8
8
|
entityManager: EntityManager;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
columns: TKeysOf<TEntity, TTableMeta>;
|
|
10
|
+
table: string;
|
|
11
|
+
schema: string;
|
|
12
12
|
debug: boolean;
|
|
13
13
|
constructor(entityType: any, entityManager: EntityManager);
|
|
14
14
|
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
@@ -21,7 +21,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
|
|
|
21
21
|
softDelete(options: FindOptionsWhere<TEntity>): Promise<void>;
|
|
22
22
|
put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
23
23
|
patch(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
24
|
-
get repo():
|
|
24
|
+
get repo(): Repository<ObjectLiteral>;
|
|
25
25
|
protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
|
|
26
26
|
protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
|
|
27
27
|
protected getSchemaPrefix(): string;
|