@onivoro/server-typeorm-postgres 22.0.12 → 22.0.13
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/index.d.ts +28 -0
- package/dist/cjs/index.js +44 -0
- package/dist/cjs/lib/classes/column-migration-base.class.d.ts +8 -0
- package/dist/cjs/lib/classes/column-migration-base.class.js +19 -0
- package/dist/cjs/lib/classes/columns-migration-base.class.d.ts +8 -0
- package/dist/cjs/lib/classes/columns-migration-base.class.js +19 -0
- package/dist/cjs/lib/classes/drop-column-migration-base.class.d.ts +8 -0
- package/dist/cjs/lib/classes/drop-column-migration-base.class.js +19 -0
- package/dist/cjs/lib/classes/drop-table-migration-base.class.d.ts +8 -0
- package/dist/cjs/lib/classes/drop-table-migration-base.class.js +19 -0
- package/dist/cjs/lib/classes/index-migration-base.class.d.ts +8 -0
- package/dist/cjs/lib/classes/index-migration-base.class.js +19 -0
- package/dist/cjs/lib/classes/redshift-repository.class.d.ts +29 -0
- package/dist/cjs/lib/classes/redshift-repository.class.js +129 -0
- package/dist/cjs/lib/classes/sql-writer.class.d.ts +14 -0
- package/dist/cjs/lib/classes/sql-writer.class.js +53 -0
- package/dist/cjs/lib/classes/table-migration-base.class.d.ts +8 -0
- package/dist/cjs/lib/classes/table-migration-base.class.js +19 -0
- package/dist/cjs/lib/classes/type-orm-paging-repository.class.d.ts +14 -0
- package/dist/cjs/lib/classes/type-orm-paging-repository.class.js +16 -0
- package/dist/cjs/lib/classes/type-orm-repository.class.d.ts +62 -0
- package/dist/cjs/lib/classes/type-orm-repository.class.js +202 -0
- package/dist/cjs/lib/constants/many-to-one-relation-options.constant.d.ts +2 -0
- package/dist/cjs/lib/constants/many-to-one-relation-options.constant.js +4 -0
- package/dist/cjs/lib/decorators/nullable-table-column.decorator.d.ts +2 -0
- package/dist/cjs/lib/decorators/nullable-table-column.decorator.js +12 -0
- package/dist/cjs/lib/decorators/primary-table-column.decorator.d.ts +2 -0
- package/dist/cjs/lib/decorators/primary-table-column.decorator.js +12 -0
- package/dist/cjs/lib/decorators/table-column.decorator.d.ts +2 -0
- package/dist/cjs/lib/decorators/table-column.decorator.js +12 -0
- package/dist/cjs/lib/decorators/table.decorator.d.ts +3 -0
- package/dist/cjs/lib/decorators/table.decorator.js +11 -0
- package/dist/cjs/lib/functions/data-source-config-factory.function.d.ts +3 -0
- package/dist/cjs/lib/functions/data-source-config-factory.function.js +25 -0
- package/dist/cjs/lib/functions/data-source-factory.function.d.ts +3 -0
- package/dist/cjs/lib/functions/data-source-factory.function.js +7 -0
- package/dist/cjs/lib/functions/generate-date-query.function.d.ts +2 -0
- package/dist/cjs/lib/functions/generate-date-query.function.js +16 -0
- package/dist/cjs/lib/functions/get-api-type-from-column.function.d.ts +2 -0
- package/dist/cjs/lib/functions/get-api-type-from-column.function.js +14 -0
- package/dist/cjs/lib/functions/get-paging-key.function.d.ts +1 -0
- package/dist/cjs/lib/functions/get-paging-key.function.js +6 -0
- package/dist/cjs/lib/functions/get-skip.function.d.ts +1 -0
- package/dist/cjs/lib/functions/get-skip.function.js +6 -0
- package/dist/cjs/lib/functions/remove-falsey-keys.function.d.ts +1 -0
- package/dist/cjs/lib/functions/remove-falsey-keys.function.js +11 -0
- package/dist/cjs/lib/server-typeorm-postgres.module.d.ts +5 -0
- package/dist/cjs/lib/server-typeorm-postgres.module.js +49 -0
- package/dist/cjs/lib/types/data-source-options.interface.d.ts +11 -0
- package/dist/cjs/lib/types/data-source-options.interface.js +2 -0
- package/dist/cjs/lib/types/entity-provider.interface.d.ts +9 -0
- package/dist/cjs/lib/types/entity-provider.interface.js +2 -0
- package/dist/cjs/lib/types/page-params.interface.d.ts +4 -0
- package/dist/cjs/lib/types/page-params.interface.js +2 -0
- package/dist/cjs/lib/types/paged-data.interface.d.ts +6 -0
- package/dist/cjs/lib/types/paged-data.interface.js +2 -0
- package/dist/cjs/lib/types/table-meta.type.d.ts +9 -0
- package/dist/cjs/lib/types/table-meta.type.js +2 -0
- package/dist/esm/lib/classes/type-orm-repository.class.d.ts +1 -1
- package/dist/esm/lib/classes/type-orm-repository.class.js +1 -1
- package/dist/types/index.d.ts +28 -0
- package/dist/types/lib/classes/column-migration-base.class.d.ts +8 -0
- package/dist/types/lib/classes/columns-migration-base.class.d.ts +8 -0
- package/dist/types/lib/classes/drop-column-migration-base.class.d.ts +8 -0
- package/dist/types/lib/classes/drop-table-migration-base.class.d.ts +8 -0
- package/dist/types/lib/classes/index-migration-base.class.d.ts +8 -0
- package/dist/types/lib/classes/redshift-repository.class.d.ts +29 -0
- package/dist/types/lib/classes/sql-writer.class.d.ts +14 -0
- package/dist/types/lib/classes/table-migration-base.class.d.ts +8 -0
- package/dist/types/lib/classes/type-orm-paging-repository.class.d.ts +14 -0
- package/dist/types/lib/classes/type-orm-repository.class.d.ts +62 -0
- package/dist/types/lib/constants/many-to-one-relation-options.constant.d.ts +2 -0
- package/dist/types/lib/decorators/nullable-table-column.decorator.d.ts +2 -0
- package/dist/types/lib/decorators/primary-table-column.decorator.d.ts +2 -0
- package/dist/types/lib/decorators/table-column.decorator.d.ts +2 -0
- package/dist/types/lib/decorators/table.decorator.d.ts +3 -0
- package/dist/types/lib/functions/data-source-config-factory.function.d.ts +3 -0
- package/dist/types/lib/functions/data-source-factory.function.d.ts +3 -0
- package/dist/types/lib/functions/generate-date-query.function.d.ts +2 -0
- package/dist/types/lib/functions/get-api-type-from-column.function.d.ts +2 -0
- package/dist/types/lib/functions/get-paging-key.function.d.ts +1 -0
- package/dist/types/lib/functions/get-skip.function.d.ts +1 -0
- package/dist/types/lib/functions/remove-falsey-keys.function.d.ts +1 -0
- package/dist/types/lib/server-typeorm-postgres.module.d.ts +5 -0
- package/dist/types/lib/types/data-source-options.interface.d.ts +11 -0
- package/dist/types/lib/types/entity-provider.interface.d.ts +9 -0
- package/dist/types/lib/types/page-params.interface.d.ts +4 -0
- package/dist/types/lib/types/paged-data.interface.d.ts +6 -0
- package/dist/types/lib/types/table-meta.type.d.ts +9 -0
- package/package.json +6 -6
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export * from './lib/classes/column-migration-base.class';
|
|
2
|
+
export * from './lib/classes/columns-migration-base.class';
|
|
3
|
+
export * from './lib/classes/drop-column-migration-base.class';
|
|
4
|
+
export * from './lib/classes/drop-table-migration-base.class';
|
|
5
|
+
export * from './lib/classes/index-migration-base.class';
|
|
6
|
+
export * from './lib/classes/redshift-repository.class';
|
|
7
|
+
export * from './lib/classes/sql-writer.class';
|
|
8
|
+
export * from './lib/classes/table-migration-base.class';
|
|
9
|
+
export * from './lib/classes/type-orm-paging-repository.class';
|
|
10
|
+
export * from './lib/classes/type-orm-repository.class';
|
|
11
|
+
export * from './lib/constants/many-to-one-relation-options.constant';
|
|
12
|
+
export * from './lib/decorators/nullable-table-column.decorator';
|
|
13
|
+
export * from './lib/decorators/primary-table-column.decorator';
|
|
14
|
+
export * from './lib/decorators/table-column.decorator';
|
|
15
|
+
export * from './lib/decorators/table.decorator';
|
|
16
|
+
export * from './lib/functions/data-source-config-factory.function';
|
|
17
|
+
export * from './lib/functions/data-source-factory.function';
|
|
18
|
+
export * from './lib/functions/generate-date-query.function';
|
|
19
|
+
export * from './lib/functions/get-api-type-from-column.function';
|
|
20
|
+
export * from './lib/functions/get-paging-key.function';
|
|
21
|
+
export * from './lib/functions/get-skip.function';
|
|
22
|
+
export * from './lib/functions/remove-falsey-keys.function';
|
|
23
|
+
export * from './lib/types/data-source-options.interface';
|
|
24
|
+
export * from './lib/types/entity-provider.interface';
|
|
25
|
+
export * from './lib/types/page-params.interface';
|
|
26
|
+
export * from './lib/types/paged-data.interface';
|
|
27
|
+
export * from './lib/types/table-meta.type';
|
|
28
|
+
export * from './lib/server-typeorm-postgres.module';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./lib/classes/column-migration-base.class"), exports);
|
|
18
|
+
__exportStar(require("./lib/classes/columns-migration-base.class"), exports);
|
|
19
|
+
__exportStar(require("./lib/classes/drop-column-migration-base.class"), exports);
|
|
20
|
+
__exportStar(require("./lib/classes/drop-table-migration-base.class"), exports);
|
|
21
|
+
__exportStar(require("./lib/classes/index-migration-base.class"), exports);
|
|
22
|
+
__exportStar(require("./lib/classes/redshift-repository.class"), exports);
|
|
23
|
+
__exportStar(require("./lib/classes/sql-writer.class"), exports);
|
|
24
|
+
__exportStar(require("./lib/classes/table-migration-base.class"), exports);
|
|
25
|
+
__exportStar(require("./lib/classes/type-orm-paging-repository.class"), exports);
|
|
26
|
+
__exportStar(require("./lib/classes/type-orm-repository.class"), exports);
|
|
27
|
+
__exportStar(require("./lib/constants/many-to-one-relation-options.constant"), exports);
|
|
28
|
+
__exportStar(require("./lib/decorators/nullable-table-column.decorator"), exports);
|
|
29
|
+
__exportStar(require("./lib/decorators/primary-table-column.decorator"), exports);
|
|
30
|
+
__exportStar(require("./lib/decorators/table-column.decorator"), exports);
|
|
31
|
+
__exportStar(require("./lib/decorators/table.decorator"), exports);
|
|
32
|
+
__exportStar(require("./lib/functions/data-source-config-factory.function"), exports);
|
|
33
|
+
__exportStar(require("./lib/functions/data-source-factory.function"), exports);
|
|
34
|
+
__exportStar(require("./lib/functions/generate-date-query.function"), exports);
|
|
35
|
+
__exportStar(require("./lib/functions/get-api-type-from-column.function"), exports);
|
|
36
|
+
__exportStar(require("./lib/functions/get-paging-key.function"), exports);
|
|
37
|
+
__exportStar(require("./lib/functions/get-skip.function"), exports);
|
|
38
|
+
__exportStar(require("./lib/functions/remove-falsey-keys.function"), exports);
|
|
39
|
+
__exportStar(require("./lib/types/data-source-options.interface"), exports);
|
|
40
|
+
__exportStar(require("./lib/types/entity-provider.interface"), exports);
|
|
41
|
+
__exportStar(require("./lib/types/page-params.interface"), exports);
|
|
42
|
+
__exportStar(require("./lib/types/paged-data.interface"), exports);
|
|
43
|
+
__exportStar(require("./lib/types/table-meta.type"), exports);
|
|
44
|
+
__exportStar(require("./lib/server-typeorm-postgres.module"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner, TableColumnOptions } from "typeorm";
|
|
2
|
+
export declare class ColumnMigrationBase implements MigrationInterface {
|
|
3
|
+
table: string;
|
|
4
|
+
option: TableColumnOptions;
|
|
5
|
+
constructor(table: string, option: TableColumnOptions);
|
|
6
|
+
up(queryRunner: QueryRunner): Promise<void>;
|
|
7
|
+
down(queryRunner: QueryRunner): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColumnMigrationBase = void 0;
|
|
4
|
+
const sql_writer_class_1 = require("./sql-writer.class");
|
|
5
|
+
class ColumnMigrationBase {
|
|
6
|
+
table;
|
|
7
|
+
option;
|
|
8
|
+
constructor(table, option) {
|
|
9
|
+
this.table = table;
|
|
10
|
+
this.option = option;
|
|
11
|
+
}
|
|
12
|
+
async up(queryRunner) {
|
|
13
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.addColumn(this.table, this.option));
|
|
14
|
+
}
|
|
15
|
+
async down(queryRunner) {
|
|
16
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.dropColumn(this.table, this.option));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ColumnMigrationBase = ColumnMigrationBase;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner, TableColumnOptions } from "typeorm";
|
|
2
|
+
export declare class ColumnsMigrationBase implements MigrationInterface {
|
|
3
|
+
table: string;
|
|
4
|
+
options: TableColumnOptions[];
|
|
5
|
+
constructor(table: string, options: TableColumnOptions[]);
|
|
6
|
+
up(queryRunner: QueryRunner): Promise<void>;
|
|
7
|
+
down(queryRunner: QueryRunner): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColumnsMigrationBase = void 0;
|
|
4
|
+
const sql_writer_class_1 = require("./sql-writer.class");
|
|
5
|
+
class ColumnsMigrationBase {
|
|
6
|
+
table;
|
|
7
|
+
options;
|
|
8
|
+
constructor(table, options) {
|
|
9
|
+
this.table = table;
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
async up(queryRunner) {
|
|
13
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.addColumns(this.table, this.options));
|
|
14
|
+
}
|
|
15
|
+
async down(queryRunner) {
|
|
16
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.dropColumns(this.table, this.options));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ColumnsMigrationBase = ColumnsMigrationBase;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner, TableColumnOptions } from "typeorm";
|
|
2
|
+
export declare class DropColumnMigrationBase implements MigrationInterface {
|
|
3
|
+
table: string;
|
|
4
|
+
option: TableColumnOptions;
|
|
5
|
+
constructor(table: string, option: TableColumnOptions);
|
|
6
|
+
down(queryRunner: QueryRunner): Promise<void>;
|
|
7
|
+
up(queryRunner: QueryRunner): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DropColumnMigrationBase = void 0;
|
|
4
|
+
const sql_writer_class_1 = require("./sql-writer.class");
|
|
5
|
+
class DropColumnMigrationBase {
|
|
6
|
+
table;
|
|
7
|
+
option;
|
|
8
|
+
constructor(table, option) {
|
|
9
|
+
this.table = table;
|
|
10
|
+
this.option = option;
|
|
11
|
+
}
|
|
12
|
+
async down(queryRunner) {
|
|
13
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.addColumn(this.table, this.option));
|
|
14
|
+
}
|
|
15
|
+
async up(queryRunner) {
|
|
16
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.dropColumn(this.table, this.option));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DropColumnMigrationBase = DropColumnMigrationBase;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner, TableColumnOptions } from "typeorm";
|
|
2
|
+
export declare class DropTableMigrationBase implements MigrationInterface {
|
|
3
|
+
table: string;
|
|
4
|
+
options: TableColumnOptions[];
|
|
5
|
+
constructor(table: string, options: TableColumnOptions[]);
|
|
6
|
+
down(queryRunner: QueryRunner): Promise<void>;
|
|
7
|
+
up(queryRunner: QueryRunner): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DropTableMigrationBase = void 0;
|
|
4
|
+
const sql_writer_class_1 = require("./sql-writer.class");
|
|
5
|
+
class DropTableMigrationBase {
|
|
6
|
+
table;
|
|
7
|
+
options;
|
|
8
|
+
constructor(table, options) {
|
|
9
|
+
this.table = table;
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
async down(queryRunner) {
|
|
13
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.createTable(this.table, this.options));
|
|
14
|
+
}
|
|
15
|
+
async up(queryRunner) {
|
|
16
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.dropTable(this.table));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DropTableMigrationBase = DropTableMigrationBase;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner, TableColumnOptions } from "typeorm";
|
|
2
|
+
export declare class UniqueIndexMigrationBase implements MigrationInterface {
|
|
3
|
+
table: string;
|
|
4
|
+
option: TableColumnOptions;
|
|
5
|
+
constructor(table: string, option: TableColumnOptions);
|
|
6
|
+
up(queryRunner: QueryRunner): Promise<void>;
|
|
7
|
+
down(queryRunner: QueryRunner): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueIndexMigrationBase = void 0;
|
|
4
|
+
const sql_writer_class_1 = require("./sql-writer.class");
|
|
5
|
+
class UniqueIndexMigrationBase {
|
|
6
|
+
table;
|
|
7
|
+
option;
|
|
8
|
+
constructor(table, option) {
|
|
9
|
+
this.table = table;
|
|
10
|
+
this.option = option;
|
|
11
|
+
}
|
|
12
|
+
async up(queryRunner) {
|
|
13
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.createUniqueIndex(this.table, this.option.name));
|
|
14
|
+
}
|
|
15
|
+
async down(queryRunner) {
|
|
16
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.dropIndex(sql_writer_class_1.SqlWriter.getIndexName(this.table, this.option.name)));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.UniqueIndexMigrationBase = UniqueIndexMigrationBase;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DataSource, EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
|
|
2
|
+
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
|
|
3
|
+
import { TypeOrmRepository } from './type-orm-repository.class';
|
|
4
|
+
import { TTableMeta } from '../types/table-meta.type';
|
|
5
|
+
import { TKeysOf } from '@onivoro/isomorphic-common';
|
|
6
|
+
export declare class RedshiftRepository<TEntity> extends TypeOrmRepository<TEntity> {
|
|
7
|
+
entityType: any;
|
|
8
|
+
entityManager: EntityManager;
|
|
9
|
+
constructor(entityType: any, entityManager: EntityManager);
|
|
10
|
+
getMany(options: FindManyOptions<TEntity>): Promise<TEntity[]>;
|
|
11
|
+
getOne(options: FindOneOptions<TEntity>): Promise<TEntity>;
|
|
12
|
+
delete(where: FindOptionsWhere<TEntity>): Promise<void>;
|
|
13
|
+
patch(where: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
14
|
+
postOne(entity: Partial<TEntity>): Promise<TEntity>;
|
|
15
|
+
postMany(entities: Partial<TEntity>[]): Promise<TEntity[]>;
|
|
16
|
+
put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
17
|
+
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
18
|
+
getManyAndCount(options: FindManyOptions<TEntity>): Promise<[TEntity[], number]>;
|
|
19
|
+
softDelete(where: FindOptionsWhere<TEntity>): Promise<void>;
|
|
20
|
+
postOneWithoutReturn(entity: Partial<TEntity>): Promise<void>;
|
|
21
|
+
postManyWithoutReturn(entities: Partial<TEntity>[]): Promise<void>;
|
|
22
|
+
private throwNotImplemented;
|
|
23
|
+
protected mapPlaceholderExpression(length: number, index: number, column: string): string;
|
|
24
|
+
static buildFromMetadata<TGenericEntity>(dataSource: DataSource, _: {
|
|
25
|
+
schema: string;
|
|
26
|
+
table: string;
|
|
27
|
+
columns: TKeysOf<TGenericEntity, TTableMeta>;
|
|
28
|
+
}): RedshiftRepository<TGenericEntity>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var RedshiftRepository_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.RedshiftRepository = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const typeorm_1 = require("typeorm");
|
|
16
|
+
const type_orm_repository_class_1 = require("./type-orm-repository.class");
|
|
17
|
+
let RedshiftRepository = RedshiftRepository_1 = class RedshiftRepository extends type_orm_repository_class_1.TypeOrmRepository {
|
|
18
|
+
entityType;
|
|
19
|
+
entityManager;
|
|
20
|
+
constructor(entityType, entityManager) {
|
|
21
|
+
super(entityType, entityManager);
|
|
22
|
+
this.entityType = entityType;
|
|
23
|
+
this.entityManager = entityManager;
|
|
24
|
+
}
|
|
25
|
+
async getMany(options) {
|
|
26
|
+
const { query, queryParams } = this.buildSelectStatement(options);
|
|
27
|
+
return await this.queryAndMap(query, queryParams.map(_ => _.value ? _.value : _));
|
|
28
|
+
}
|
|
29
|
+
async getOne(options) {
|
|
30
|
+
const results = await this.getMany(options);
|
|
31
|
+
if (results.length > 1) {
|
|
32
|
+
throw new Error(`RedshiftRepository.getOne expected one result but found ${results.length} results`);
|
|
33
|
+
}
|
|
34
|
+
return results[0];
|
|
35
|
+
}
|
|
36
|
+
async delete(where) {
|
|
37
|
+
const { query, queryParams } = this.buildDeleteStatement(where);
|
|
38
|
+
await this.query(query, queryParams);
|
|
39
|
+
}
|
|
40
|
+
async patch(where, body) {
|
|
41
|
+
const queryParams = [];
|
|
42
|
+
let whereClause = '';
|
|
43
|
+
Object.entries(where).forEach(([propertyPath, value], index) => {
|
|
44
|
+
const key = this.columns[propertyPath].databasePath;
|
|
45
|
+
if (index === 0) {
|
|
46
|
+
whereClause += ` WHERE ${key} = ${this.mapPlaceholderExpression(0, index, propertyPath)}`;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
whereClause += ` AND ${key} = ${this.mapPlaceholderExpression(0, index, propertyPath)}`;
|
|
50
|
+
}
|
|
51
|
+
queryParams.push(value);
|
|
52
|
+
});
|
|
53
|
+
const setParams = [];
|
|
54
|
+
let setExpressions = [];
|
|
55
|
+
const length = queryParams?.length;
|
|
56
|
+
Object.entries(body).forEach(([key, value], index) => {
|
|
57
|
+
setExpressions.push(`${this.columns[key].databasePath} = ${this.mapPlaceholderExpression(length, index, key)}`);
|
|
58
|
+
setParams.push(value);
|
|
59
|
+
});
|
|
60
|
+
let query = `UPDATE ${this.getTableNameExpression()} SET ${setExpressions.join(', ')} ${whereClause}`;
|
|
61
|
+
await this.query(query, [...queryParams, ...setParams]);
|
|
62
|
+
}
|
|
63
|
+
async postOne(entity) {
|
|
64
|
+
await this.postOneWithoutReturn(entity);
|
|
65
|
+
return await this.getOne({ where: entity });
|
|
66
|
+
}
|
|
67
|
+
async postMany(entities) {
|
|
68
|
+
if (entities?.length) {
|
|
69
|
+
const { insertQuery, values } = this.buildInsertManyQuery(entities);
|
|
70
|
+
await this.query(insertQuery, values);
|
|
71
|
+
const { selectQuery, values: selectValues } = this.buildSelectManyQuery(entities);
|
|
72
|
+
return await this.queryAndMap(selectQuery, selectValues);
|
|
73
|
+
}
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
async put(options, body) {
|
|
77
|
+
this.throwNotImplemented('put');
|
|
78
|
+
}
|
|
79
|
+
forTransaction(entityManager) {
|
|
80
|
+
this.throwNotImplemented('forTransaction');
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
async getManyAndCount(options) {
|
|
84
|
+
this.throwNotImplemented('getManyAndCount');
|
|
85
|
+
return [[], 0];
|
|
86
|
+
}
|
|
87
|
+
async softDelete(where) {
|
|
88
|
+
await this.patch(where, { deletedAt: new Date().toISOString() });
|
|
89
|
+
}
|
|
90
|
+
async postOneWithoutReturn(entity) {
|
|
91
|
+
// PERFORM AN INSERT BUT NOT THE RETRIEVAL QUERY FOR PERFORMANCE
|
|
92
|
+
const { insertQuery, values } = this.buildInsertQuery(entity);
|
|
93
|
+
await this.query(insertQuery, values);
|
|
94
|
+
}
|
|
95
|
+
async postManyWithoutReturn(entities) {
|
|
96
|
+
// TODO: PERFORM AN INSERT BUT NOT THE RETRIEVAL QUERY FOR PERFORMANCE
|
|
97
|
+
// TODO: THIS IS ACTUALLY NEEDED TO HELP WITH LARGE DATASETS
|
|
98
|
+
this.throwNotImplemented('postManyWithoutReturn');
|
|
99
|
+
}
|
|
100
|
+
throwNotImplemented(feature) {
|
|
101
|
+
throw new common_1.NotImplementedException(`RedshiftRepository of type "${this.entityType?.name}" has no implementation for "${feature}"`);
|
|
102
|
+
}
|
|
103
|
+
mapPlaceholderExpression(length, index, column) {
|
|
104
|
+
const exp = `$${length + index + 1}`;
|
|
105
|
+
const meta = this.columns[column];
|
|
106
|
+
return meta.type === 'jsonb' ? `JSON_PARSE(${exp})` : exp;
|
|
107
|
+
}
|
|
108
|
+
static buildFromMetadata(dataSource, _) {
|
|
109
|
+
class GenericRepository extends RedshiftRepository_1 {
|
|
110
|
+
constructor() {
|
|
111
|
+
const entityManager = dataSource.createEntityManager();
|
|
112
|
+
super(Object, {
|
|
113
|
+
...entityManager,
|
|
114
|
+
getRepository: () => entityManager
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const genericRepository = new GenericRepository();
|
|
119
|
+
genericRepository.schema = _.schema;
|
|
120
|
+
genericRepository.table = _.table;
|
|
121
|
+
genericRepository.columns = _.columns;
|
|
122
|
+
return genericRepository;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
exports.RedshiftRepository = RedshiftRepository;
|
|
126
|
+
exports.RedshiftRepository = RedshiftRepository = RedshiftRepository_1 = __decorate([
|
|
127
|
+
(0, common_1.Injectable)(),
|
|
128
|
+
__metadata("design:paramtypes", [Object, typeorm_1.EntityManager])
|
|
129
|
+
], RedshiftRepository);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TableColumnOptions } from "typeorm";
|
|
2
|
+
export declare class SqlWriter {
|
|
3
|
+
static addColumn(table: string, option: TableColumnOptions): string;
|
|
4
|
+
static createTable(table: string, options: TableColumnOptions[]): string;
|
|
5
|
+
static dropTable(table: string): string;
|
|
6
|
+
static addColumns(table: string, options: TableColumnOptions[]): string;
|
|
7
|
+
static dropColumn(table: string, option: TableColumnOptions): string;
|
|
8
|
+
static dropColumns(table: string, options: TableColumnOptions[]): string;
|
|
9
|
+
static dropIndex(index: string): string;
|
|
10
|
+
static createIndex(table: string, column: string, unique: boolean): string;
|
|
11
|
+
static getIndexName(table: string, column: string): string;
|
|
12
|
+
static createUniqueIndex(table: string, column: string): string;
|
|
13
|
+
static getDefaultValueExpression(option: TableColumnOptions): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqlWriter = void 0;
|
|
4
|
+
class SqlWriter {
|
|
5
|
+
static addColumn(table, option) {
|
|
6
|
+
const notNullExpression = option.isPrimary ? ` PRIMARY KEY ` : (option.isNullable ? '' : ' NOT NULL ');
|
|
7
|
+
const foreignKey = option.foreignKeyConstraintName ? ` REFERENCES ${option.foreignKeyConstraintName} ` : '';
|
|
8
|
+
const uniqueExpression = option.isUnique ? ' UNIQUE ' : '';
|
|
9
|
+
return `ALTER TABLE "${table}" ADD "${option.name}" ${option.type}${notNullExpression}${uniqueExpression}${SqlWriter.getDefaultValueExpression(option)}${foreignKey}`;
|
|
10
|
+
}
|
|
11
|
+
static createTable(table, options) {
|
|
12
|
+
const cols = options.map(option => SqlWriter.addColumn(table, option).replace(`ALTER TABLE "${table}" ADD `, '')).join(',\n');
|
|
13
|
+
return `CREATE TABLE "${table}" (${cols});`;
|
|
14
|
+
}
|
|
15
|
+
static dropTable(table) {
|
|
16
|
+
return `DROP TABLE "${table}";\n`;
|
|
17
|
+
}
|
|
18
|
+
static addColumns(table, options) {
|
|
19
|
+
return options.map(option => SqlWriter.addColumn(table, option)).join('; \n');
|
|
20
|
+
}
|
|
21
|
+
static dropColumn(table, option) {
|
|
22
|
+
return `ALTER TABLE "${table}" DROP COLUMN ${option.name}`;
|
|
23
|
+
}
|
|
24
|
+
static dropColumns(table, options) {
|
|
25
|
+
return options.map(option => SqlWriter.dropColumn(table, option)).join('; \n');
|
|
26
|
+
}
|
|
27
|
+
static dropIndex(index) {
|
|
28
|
+
return `DROP INDEX IF EXISTS ${index}`;
|
|
29
|
+
}
|
|
30
|
+
static createIndex(table, column, unique) {
|
|
31
|
+
const index = SqlWriter.getIndexName(table, column);
|
|
32
|
+
return `CREATE ${unique ? 'UNIQUE' : ''} INDEX IF NOT EXISTS ${index} ON "${table}"(${column})`;
|
|
33
|
+
}
|
|
34
|
+
static getIndexName(table, column) {
|
|
35
|
+
return `${table}_${column}`;
|
|
36
|
+
}
|
|
37
|
+
static createUniqueIndex(table, column) {
|
|
38
|
+
return SqlWriter.createIndex(table, column, true);
|
|
39
|
+
}
|
|
40
|
+
static getDefaultValueExpression(option) {
|
|
41
|
+
if (typeof option.default === 'undefined') {
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
if (['json', 'jsonb'].includes(option.type)) {
|
|
45
|
+
return ` DEFAULT '${JSON.stringify(option.default)}'::${option.type} `;
|
|
46
|
+
}
|
|
47
|
+
if (['boolean', 'bigint', 'int'].includes(option.type)) {
|
|
48
|
+
return ` DEFAULT ${option.default.toString().toUpperCase()} `;
|
|
49
|
+
}
|
|
50
|
+
return ` DEFAULT '${option.default}' `;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.SqlWriter = SqlWriter;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner, TableColumnOptions } from "typeorm";
|
|
2
|
+
export declare class TableMigrationBase implements MigrationInterface {
|
|
3
|
+
table: string;
|
|
4
|
+
options: TableColumnOptions[];
|
|
5
|
+
constructor(table: string, options: TableColumnOptions[]);
|
|
6
|
+
up(queryRunner: QueryRunner): Promise<void>;
|
|
7
|
+
down(queryRunner: QueryRunner): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableMigrationBase = void 0;
|
|
4
|
+
const sql_writer_class_1 = require("./sql-writer.class");
|
|
5
|
+
class TableMigrationBase {
|
|
6
|
+
table;
|
|
7
|
+
options;
|
|
8
|
+
constructor(table, options) {
|
|
9
|
+
this.table = table;
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
async up(queryRunner) {
|
|
13
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.createTable(this.table, this.options));
|
|
14
|
+
}
|
|
15
|
+
async down(queryRunner) {
|
|
16
|
+
await queryRunner.query(sql_writer_class_1.SqlWriter.dropTable(this.table));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.TableMigrationBase = TableMigrationBase;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EntityManager } from 'typeorm';
|
|
2
|
+
import { TypeOrmRepository } from './type-orm-repository.class';
|
|
3
|
+
import { IPagedData } from '../types/paged-data.interface';
|
|
4
|
+
import { getSkip } from '../functions/get-skip.function';
|
|
5
|
+
import { removeFalseyKeys } from '../functions/remove-falsey-keys.function';
|
|
6
|
+
import { getPagingKey } from '../functions/get-paging-key.function';
|
|
7
|
+
import { IPageParams } from '../types/page-params.interface';
|
|
8
|
+
export declare abstract class TypeOrmPagingRepository<TEntity, TEntityParams> extends TypeOrmRepository<TEntity> {
|
|
9
|
+
protected getPagingKey: typeof getPagingKey;
|
|
10
|
+
protected getSkip: typeof getSkip;
|
|
11
|
+
protected removeFalseyKeys: typeof removeFalseyKeys;
|
|
12
|
+
constructor(entityType: any, entityManager: EntityManager);
|
|
13
|
+
abstract getPage(pageParams: IPageParams, params: TEntityParams): Promise<IPagedData<TEntity>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeOrmPagingRepository = void 0;
|
|
4
|
+
const type_orm_repository_class_1 = require("./type-orm-repository.class");
|
|
5
|
+
const get_skip_function_1 = require("../functions/get-skip.function");
|
|
6
|
+
const remove_falsey_keys_function_1 = require("../functions/remove-falsey-keys.function");
|
|
7
|
+
const get_paging_key_function_1 = require("../functions/get-paging-key.function");
|
|
8
|
+
class TypeOrmPagingRepository extends type_orm_repository_class_1.TypeOrmRepository {
|
|
9
|
+
getPagingKey = get_paging_key_function_1.getPagingKey;
|
|
10
|
+
getSkip = get_skip_function_1.getSkip;
|
|
11
|
+
removeFalseyKeys = remove_falsey_keys_function_1.removeFalseyKeys;
|
|
12
|
+
constructor(entityType, entityManager) {
|
|
13
|
+
super(entityType, entityManager);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.TypeOrmPagingRepository = TypeOrmPagingRepository;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DataSource, EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
|
|
2
|
+
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
|
|
3
|
+
import { IEntityProvider } from '../types/entity-provider.interface';
|
|
4
|
+
import { TKeysOf } from '@onivoro/isomorphic-common';
|
|
5
|
+
import { TTableMeta } from '../types/table-meta.type';
|
|
6
|
+
export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEntity, FindOneOptions<TEntity>, FindManyOptions<TEntity>, FindOptionsWhere<TEntity>, QueryDeepPartialEntity<TEntity>> {
|
|
7
|
+
entityType: any;
|
|
8
|
+
entityManager: EntityManager;
|
|
9
|
+
columns: TKeysOf<TEntity, TTableMeta>;
|
|
10
|
+
table: string;
|
|
11
|
+
schema: string;
|
|
12
|
+
debug: boolean;
|
|
13
|
+
constructor(entityType: any, entityManager: EntityManager);
|
|
14
|
+
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
15
|
+
getMany(options: FindManyOptions<TEntity>): Promise<TEntity[]>;
|
|
16
|
+
getManyAndCount(options: FindManyOptions<TEntity>): Promise<[TEntity[], number]>;
|
|
17
|
+
getOne(options: FindOneOptions<TEntity>): Promise<TEntity>;
|
|
18
|
+
postOne(body: Partial<TEntity>): Promise<TEntity>;
|
|
19
|
+
postMany(body: Partial<TEntity>[]): Promise<TEntity[]>;
|
|
20
|
+
delete(options: FindOptionsWhere<TEntity>): Promise<void>;
|
|
21
|
+
softDelete(options: FindOptionsWhere<TEntity>): Promise<void>;
|
|
22
|
+
put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
23
|
+
patch(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
24
|
+
get repo(): import("typeorm").Repository<import("typeorm").ObjectLiteral>;
|
|
25
|
+
protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
|
|
26
|
+
protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
|
|
27
|
+
protected getSchemaPrefix(): string;
|
|
28
|
+
protected getTableNameExpression(): string;
|
|
29
|
+
protected buildSelectStatement(options: FindManyOptions<TEntity>): {
|
|
30
|
+
query: string;
|
|
31
|
+
queryParams: any[];
|
|
32
|
+
};
|
|
33
|
+
protected buildDeleteStatement(where: FindManyOptions<TEntity>): {
|
|
34
|
+
query: string;
|
|
35
|
+
queryParams: any[];
|
|
36
|
+
};
|
|
37
|
+
protected buildWhereExpression(where?: FindOptionsWhere<TEntity>): {
|
|
38
|
+
queryParams: any[];
|
|
39
|
+
whereClause: string;
|
|
40
|
+
};
|
|
41
|
+
protected buildInsertQuery(entity: Partial<TEntity>): {
|
|
42
|
+
insertQuery: string;
|
|
43
|
+
values: any[];
|
|
44
|
+
};
|
|
45
|
+
protected buildInsertManyQuery(entities: Partial<TEntity>[]): {
|
|
46
|
+
insertQuery: string;
|
|
47
|
+
values: any[];
|
|
48
|
+
};
|
|
49
|
+
protected mapPlaceholderExpression(length: number, index: number, column: string): string;
|
|
50
|
+
protected buildSelectManyQuery(entities: Partial<TEntity>[]): {
|
|
51
|
+
selectQuery: string;
|
|
52
|
+
values: any[];
|
|
53
|
+
};
|
|
54
|
+
map(raw: any): TEntity;
|
|
55
|
+
query(query: string, parameters: any[]): Promise<any[]>;
|
|
56
|
+
queryAndMap(query: string, parameters: any[]): Promise<TEntity[]>;
|
|
57
|
+
static buildFromMetadata<TGenericEntity>(dataSource: DataSource, _: {
|
|
58
|
+
schema: string;
|
|
59
|
+
table: string;
|
|
60
|
+
columns: TKeysOf<TGenericEntity, TTableMeta>;
|
|
61
|
+
}): TypeOrmRepository<TGenericEntity>;
|
|
62
|
+
}
|