@node-c/persistance-rdb 1.0.0-alpha1
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/LICENSE +1 -0
- package/README.md +4 -0
- package/dist/common/definitions/common.constants.d.ts +4 -0
- package/dist/common/definitions/common.constants.js +9 -0
- package/dist/common/definitions/common.constants.js.map +1 -0
- package/dist/common/definitions/index.d.ts +1 -0
- package/dist/common/definitions/index.js +18 -0
- package/dist/common/definitions/index.js.map +1 -0
- package/dist/entityService/index.d.ts +2 -0
- package/dist/entityService/index.js +19 -0
- package/dist/entityService/index.js.map +1 -0
- package/dist/entityService/rdb.entity.service.d.ts +34 -0
- package/dist/entityService/rdb.entity.service.definitions.d.ts +21 -0
- package/dist/entityService/rdb.entity.service.definitions.js +8 -0
- package/dist/entityService/rdb.entity.service.definitions.js.map +1 -0
- package/dist/entityService/rdb.entity.service.js +304 -0
- package/dist/entityService/rdb.entity.service.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/module/index.d.ts +2 -0
- package/dist/module/index.js +19 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/rdb.module.d.ts +5 -0
- package/dist/module/rdb.module.definitions.d.ts +15 -0
- package/dist/module/rdb.module.definitions.js +3 -0
- package/dist/module/rdb.module.definitions.js.map +1 -0
- package/dist/module/rdb.module.js +45 -0
- package/dist/module/rdb.module.js.map +1 -0
- package/dist/repository/index.d.ts +2 -0
- package/dist/repository/index.js +19 -0
- package/dist/repository/index.js.map +1 -0
- package/dist/repository/rdb.repository.definitions.d.ts +5 -0
- package/dist/repository/rdb.repository.definitions.js +3 -0
- package/dist/repository/rdb.repository.definitions.js.map +1 -0
- package/dist/repository/rdb.repository.module.d.ts +6 -0
- package/dist/repository/rdb.repository.module.js +38 -0
- package/dist/repository/rdb.repository.module.js.map +1 -0
- package/dist/sqlQueryBuilder/index.d.ts +3 -0
- package/dist/sqlQueryBuilder/index.js +20 -0
- package/dist/sqlQueryBuilder/index.js.map +1 -0
- package/dist/sqlQueryBuilder/sqlQueryBuilder.definitions.d.ts +25 -0
- package/dist/sqlQueryBuilder/sqlQueryBuilder.definitions.js +3 -0
- package/dist/sqlQueryBuilder/sqlQueryBuilder.definitions.js.map +1 -0
- package/dist/sqlQueryBuilder/sqlQueryBuilder.module.d.ts +5 -0
- package/dist/sqlQueryBuilder/sqlQueryBuilder.module.js +36 -0
- package/dist/sqlQueryBuilder/sqlQueryBuilder.module.js.map +1 -0
- package/dist/sqlQueryBuilder/sqlQueryBuilder.service.d.ts +43 -0
- package/dist/sqlQueryBuilder/sqlQueryBuilder.service.js +374 -0
- package/dist/sqlQueryBuilder/sqlQueryBuilder.service.js.map +1 -0
- package/package.json +24 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Constants = void 0;
|
|
4
|
+
var Constants;
|
|
5
|
+
(function (Constants) {
|
|
6
|
+
Constants["SQL_BUILDER_DB_CONFIG_PATH"] = "SQL_BUILDER_DB_CONFIG_PATH";
|
|
7
|
+
Constants["SQL_BUILDER_SERVICE_TOKEN_SUFFIX"] = "_SQL_BUILDER_SERVICE";
|
|
8
|
+
})(Constants = exports.Constants || (exports.Constants = {}));
|
|
9
|
+
//# sourceMappingURL=common.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.constants.js","sourceRoot":"","sources":["../../../src/common/definitions/common.constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAKX;AALD,WAAY,SAAS;IAEnB,sEAAyD,CAAA;IAEzD,sEAAyD,CAAA;AAC3D,CAAC,EALW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAKpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './common.constants';
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./common.constants"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/definitions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./rdb.entity.service.definitions"), exports);
|
|
18
|
+
__exportStar(require("./rdb.entity.service"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entityService/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mEAAiD;AACjD,uDAAqC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DeleteResult, FindResults, NumberItem, PersistanceEntityService, UpdateResult } from '@node-c/core';
|
|
2
|
+
import { EntityManager, EntitySchema, EntityTarget, ObjectLiteral, Repository } from 'typeorm';
|
|
3
|
+
import { BulkCreateOptions, CountOptions, CreateOptions, DeleteOptions, FindOneOptions, FindOptions, UpdateOptions } from './rdb.entity.service.definitions';
|
|
4
|
+
import { ParsedFilter, SQLQueryBuilderService } from '../sqlQueryBuilder';
|
|
5
|
+
export declare class RDBEntityService<Entity extends ObjectLiteral> extends PersistanceEntityService<Entity> {
|
|
6
|
+
protected qb: SQLQueryBuilderService;
|
|
7
|
+
protected repository: Repository<Entity>;
|
|
8
|
+
protected schema: EntitySchema;
|
|
9
|
+
protected primaryKeys: string[];
|
|
10
|
+
constructor(qb: SQLQueryBuilderService, repository: Repository<Entity>, schema: EntitySchema);
|
|
11
|
+
protected buildPrimaryKeyWhereClause(data: Entity[]): {
|
|
12
|
+
field: string;
|
|
13
|
+
value: ParsedFilter;
|
|
14
|
+
};
|
|
15
|
+
bulkCreate(data: Entity[], options?: BulkCreateOptions): Promise<Entity[]>;
|
|
16
|
+
create(data: Entity, options?: CreateOptions): Promise<Entity>;
|
|
17
|
+
count(options: CountOptions): Promise<number | undefined>;
|
|
18
|
+
delete(options: DeleteOptions): Promise<DeleteResult>;
|
|
19
|
+
find(options: FindOptions): Promise<FindResults<Entity>>;
|
|
20
|
+
findOne(options: FindOneOptions): Promise<Entity | null>;
|
|
21
|
+
getEntityTarget(): EntityTarget<Entity>;
|
|
22
|
+
protected getRepository(transactionManager?: EntityManager): Repository<Entity>;
|
|
23
|
+
protected processManyToMany(data: {
|
|
24
|
+
counterpartColumn: string;
|
|
25
|
+
currentEntityColumn: string;
|
|
26
|
+
id: number;
|
|
27
|
+
items: NumberItem[];
|
|
28
|
+
tableName: string;
|
|
29
|
+
}, options?: {
|
|
30
|
+
transactionManager?: EntityManager;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
protected save<Data = unknown, ReturnData = unknown>(data: Data, transactionManager?: EntityManager): Promise<ReturnData>;
|
|
33
|
+
update(data: Entity, options: UpdateOptions): Promise<UpdateResult<Entity>>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CountOptions as CommonCountOptions, DeleteOptions as CommonDeleteOptions, FindOneOptions as CommonFindOneOptions, FindOptions as CommonFindOptions, UpdateOptions as CommonUpdateOptions } from '@node-c/core';
|
|
2
|
+
import { EntityManager } from 'typeorm';
|
|
3
|
+
export interface BaseOptions {
|
|
4
|
+
forceTransaction?: boolean;
|
|
5
|
+
transactionManager?: EntityManager;
|
|
6
|
+
}
|
|
7
|
+
export type BulkCreateOptions = BaseOptions;
|
|
8
|
+
export interface CountOptions extends BaseOptions, CommonCountOptions {
|
|
9
|
+
}
|
|
10
|
+
export type CreateOptions = BaseOptions;
|
|
11
|
+
export interface DeleteOptions extends BaseOptions, CommonDeleteOptions {
|
|
12
|
+
}
|
|
13
|
+
export interface FindOptions extends BaseOptions, CommonFindOptions {
|
|
14
|
+
}
|
|
15
|
+
export interface FindOneOptions extends BaseOptions, CommonFindOneOptions {
|
|
16
|
+
}
|
|
17
|
+
export declare enum PostgresErrorCode {
|
|
18
|
+
UniqueViolation = "23505"
|
|
19
|
+
}
|
|
20
|
+
export interface UpdateOptions extends BaseOptions, CommonUpdateOptions {
|
|
21
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostgresErrorCode = void 0;
|
|
4
|
+
var PostgresErrorCode;
|
|
5
|
+
(function (PostgresErrorCode) {
|
|
6
|
+
PostgresErrorCode["UniqueViolation"] = "23505";
|
|
7
|
+
})(PostgresErrorCode = exports.PostgresErrorCode || (exports.PostgresErrorCode = {}));
|
|
8
|
+
//# sourceMappingURL=rdb.entity.service.definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rdb.entity.service.definitions.js","sourceRoot":"","sources":["../../src/entityService/rdb.entity.service.definitions.ts"],"names":[],"mappings":";;;AA2BA,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAE3B,8CAAyB,CAAA;AAC3B,CAAC,EAHW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAG5B"}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RDBEntityService = void 0;
|
|
13
|
+
const core_1 = require("@node-c/core");
|
|
14
|
+
const rdb_entity_service_definitions_1 = require("./rdb.entity.service.definitions");
|
|
15
|
+
class RDBEntityService extends core_1.PersistanceEntityService {
|
|
16
|
+
constructor(qb, repository, schema) {
|
|
17
|
+
var _a;
|
|
18
|
+
super();
|
|
19
|
+
this.qb = qb;
|
|
20
|
+
this.repository = repository;
|
|
21
|
+
this.schema = schema;
|
|
22
|
+
const { columns } = schema.options;
|
|
23
|
+
const primaryKeys = [];
|
|
24
|
+
for (const columnName in columns) {
|
|
25
|
+
if ((_a = columns[columnName]) === null || _a === void 0 ? void 0 : _a.primary) {
|
|
26
|
+
primaryKeys.push(columnName);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
this.primaryKeys = primaryKeys;
|
|
30
|
+
}
|
|
31
|
+
buildPrimaryKeyWhereClause(data) {
|
|
32
|
+
const { primaryKeys, qb, repository } = this;
|
|
33
|
+
const { columnQuotesSymbol: cqs } = qb;
|
|
34
|
+
const tableName = repository.metadata.tableName;
|
|
35
|
+
if (primaryKeys.length === 1) {
|
|
36
|
+
const [primaryKey] = primaryKeys;
|
|
37
|
+
return {
|
|
38
|
+
field: primaryKey,
|
|
39
|
+
value: {
|
|
40
|
+
params: { [primaryKey]: data.map(item => item[primaryKey]) },
|
|
41
|
+
query: `${cqs}${tableName}${cqs}.${cqs}${primaryKey}${cqs} in :${primaryKey}`
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const params = {};
|
|
46
|
+
const query = [];
|
|
47
|
+
data.forEach((item, itemIndex) => {
|
|
48
|
+
const innerQuery = [];
|
|
49
|
+
primaryKeys.forEach(fieldName => {
|
|
50
|
+
const primaryKeyName = `${fieldName}${itemIndex}`;
|
|
51
|
+
params[primaryKeyName] = item[fieldName];
|
|
52
|
+
innerQuery.push(`${cqs}${tableName}${cqs}.${cqs}${fieldName}${cqs} = :${primaryKeyName}`);
|
|
53
|
+
});
|
|
54
|
+
query.push(`(${innerQuery.join(' and ')})`);
|
|
55
|
+
});
|
|
56
|
+
return { field: core_1.SelectOperator.Or, value: { params, query: `(${query.join(' or ')})` } };
|
|
57
|
+
}
|
|
58
|
+
bulkCreate(data, options) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const actualOptions = Object.assign(options || {});
|
|
61
|
+
const { forceTransaction, transactionManager } = actualOptions;
|
|
62
|
+
if (!transactionManager && forceTransaction) {
|
|
63
|
+
return this.repository.manager.transaction(tm => {
|
|
64
|
+
return this.bulkCreate(data, Object.assign(Object.assign({}, actualOptions), { transactionManager: tm }));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return yield this.save(data, transactionManager);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
create(data, options) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const actualOptions = Object.assign(options || {});
|
|
73
|
+
const { forceTransaction, transactionManager } = actualOptions;
|
|
74
|
+
if (!transactionManager && forceTransaction) {
|
|
75
|
+
return this.repository.manager.transaction(tm => {
|
|
76
|
+
return this.create(data, Object.assign(Object.assign({}, actualOptions), { transactionManager: tm }));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
return yield this.save(data, transactionManager);
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
const error = e;
|
|
84
|
+
if (error.code === rdb_entity_service_definitions_1.PostgresErrorCode.UniqueViolation) {
|
|
85
|
+
const extractVariableName = new RegExp(/^Key \((.*)\)\=(.*)$/g);
|
|
86
|
+
const result = extractVariableName.exec(error.detail);
|
|
87
|
+
throw new core_1.ApplicationError(`${error.table}: ${result ? result[1] : 'a column value you have provided'} needs to be unique`);
|
|
88
|
+
}
|
|
89
|
+
throw e;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
count(options) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const { filters, forceTransaction, transactionManager, withDeleted = false } = options;
|
|
96
|
+
if (!transactionManager && forceTransaction) {
|
|
97
|
+
return this.repository.manager.transaction(tm => {
|
|
98
|
+
return this.count(Object.assign(Object.assign({}, options), { transactionManager: tm }));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const entityName = this.repository.metadata.name;
|
|
102
|
+
const tableName = this.repository.metadata.name;
|
|
103
|
+
const queryBuilder = this.getRepository(transactionManager).createQueryBuilder(entityName);
|
|
104
|
+
const { where, include: includeFromFilters } = this.qb.parseFilters(tableName, filters);
|
|
105
|
+
const include = this.qb.parseRelations(tableName, [], includeFromFilters);
|
|
106
|
+
this.qb.buildQuery(queryBuilder, { where, include, withDeleted });
|
|
107
|
+
return yield queryBuilder.getCount();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
delete(options) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const { filters, forceTransaction, transactionManager, softDelete = true } = options;
|
|
113
|
+
if (!transactionManager && forceTransaction) {
|
|
114
|
+
return this.repository.manager.transaction(tm => {
|
|
115
|
+
return this.delete(Object.assign(Object.assign({}, options), { transactionManager: tm }));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
const entityName = this.repository.metadata.name;
|
|
119
|
+
const tableName = this.repository.metadata.tableName;
|
|
120
|
+
const deleteType = softDelete ? 'softDelete' : 'delete';
|
|
121
|
+
const queryBuilder = this.getRepository(transactionManager).createQueryBuilder(entityName)[deleteType]();
|
|
122
|
+
const { where: parsedWhere, include } = this.qb.parseFilters(tableName, filters);
|
|
123
|
+
let where = {};
|
|
124
|
+
if (Object.keys(include).length) {
|
|
125
|
+
const findData = yield this.find({ filters, transactionManager });
|
|
126
|
+
const { field, value } = this.buildPrimaryKeyWhereClause(findData.items);
|
|
127
|
+
where[field] = value;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
where = parsedWhere;
|
|
131
|
+
}
|
|
132
|
+
this.qb.buildQuery(queryBuilder, { where });
|
|
133
|
+
const result = yield queryBuilder.execute();
|
|
134
|
+
return { count: typeof result.affected === 'number' ? result.affected : undefined };
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
find(options) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const { filters, forceTransaction, page: optPage, perPage: optPerPage, findAll: optFindAll, include: optRelations, orderBy: optOrderBy, transactionManager, withDeleted = false } = options;
|
|
140
|
+
if (!transactionManager && forceTransaction) {
|
|
141
|
+
return this.repository.manager.transaction(tm => {
|
|
142
|
+
return this.find(Object.assign(Object.assign({}, options), { transactionManager: tm }));
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const page = optPage ? parseInt(optPage, 10) : 1;
|
|
146
|
+
const perPage = optPerPage ? parseInt(optPerPage, 10) : 10;
|
|
147
|
+
const findAll = optFindAll === true || optFindAll === 'true';
|
|
148
|
+
const findResults = { page: 1, perPage: 0, items: [], more: false };
|
|
149
|
+
const entityName = this.repository.metadata.name;
|
|
150
|
+
const tableName = this.repository.metadata.name;
|
|
151
|
+
const queryBuilder = this.getRepository(transactionManager).createQueryBuilder(entityName);
|
|
152
|
+
let where = {};
|
|
153
|
+
let include = {};
|
|
154
|
+
let orderBy = [];
|
|
155
|
+
if (filters) {
|
|
156
|
+
const parsedFiltersData = this.qb.parseFilters(tableName, filters);
|
|
157
|
+
where = Object.assign({}, parsedFiltersData.where);
|
|
158
|
+
include = Object.assign({}, parsedFiltersData.include);
|
|
159
|
+
}
|
|
160
|
+
include = this.qb.parseRelations(tableName, optRelations || [], include);
|
|
161
|
+
if (optOrderBy) {
|
|
162
|
+
const parsedOrderByData = this.qb.parseOrderBy(tableName, optOrderBy);
|
|
163
|
+
include = Object.assign(Object.assign({}, parsedOrderByData.include), include);
|
|
164
|
+
orderBy = [...parsedOrderByData.orderBy];
|
|
165
|
+
}
|
|
166
|
+
this.qb.buildQuery(queryBuilder, { where, include, orderBy, withDeleted });
|
|
167
|
+
if (!findAll) {
|
|
168
|
+
queryBuilder.skip((page - 1) * perPage).take(perPage + 1);
|
|
169
|
+
findResults.page = page;
|
|
170
|
+
findResults.perPage = perPage;
|
|
171
|
+
}
|
|
172
|
+
const items = yield queryBuilder.getMany();
|
|
173
|
+
if (findAll) {
|
|
174
|
+
findResults.perPage = items.length;
|
|
175
|
+
}
|
|
176
|
+
else if (items.length === perPage + 1) {
|
|
177
|
+
items.pop();
|
|
178
|
+
findResults.more = true;
|
|
179
|
+
}
|
|
180
|
+
findResults.items = items;
|
|
181
|
+
return findResults;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
findOne(options) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
const { filters, forceTransaction, transactionManager, selectOperator, include: optRelations, orderBy: optOrderBy, withDeleted = false } = options;
|
|
187
|
+
if (!transactionManager && forceTransaction) {
|
|
188
|
+
return this.repository.manager.transaction(tm => {
|
|
189
|
+
return this.findOne(Object.assign(Object.assign({}, options), { transactionManager: tm }));
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
const entityName = this.repository.metadata.name;
|
|
193
|
+
const tableName = this.repository.metadata.name;
|
|
194
|
+
const queryBuilder = this.getRepository(transactionManager).createQueryBuilder(entityName);
|
|
195
|
+
const { where, include: includeFromFilters } = this.qb.parseFilters(tableName, filters, {
|
|
196
|
+
operator: selectOperator,
|
|
197
|
+
isTopLevel: true
|
|
198
|
+
});
|
|
199
|
+
const include = this.qb.parseRelations(tableName, optRelations || [], includeFromFilters);
|
|
200
|
+
let orderBy = [];
|
|
201
|
+
if (optOrderBy) {
|
|
202
|
+
const parsedOrderByData = this.qb.parseOrderBy(tableName, optOrderBy);
|
|
203
|
+
orderBy = [...parsedOrderByData.orderBy];
|
|
204
|
+
}
|
|
205
|
+
this.qb.buildQuery(queryBuilder, { where, include, orderBy, withDeleted });
|
|
206
|
+
return yield queryBuilder.getOne();
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
getEntityTarget() {
|
|
210
|
+
return this.repository.target;
|
|
211
|
+
}
|
|
212
|
+
getRepository(transactionManager) {
|
|
213
|
+
if (transactionManager) {
|
|
214
|
+
return transactionManager.getRepository(this.repository.target);
|
|
215
|
+
}
|
|
216
|
+
return this.repository;
|
|
217
|
+
}
|
|
218
|
+
processManyToMany(data, options) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
const { currentEntityColumn, id, counterpartColumn, items, tableName } = data;
|
|
221
|
+
const actualOptions = options || {};
|
|
222
|
+
const { transactionManager } = actualOptions;
|
|
223
|
+
if (!transactionManager) {
|
|
224
|
+
return this.repository.manager.transaction(tm => {
|
|
225
|
+
return this.processManyToMany(data, Object.assign(Object.assign({}, actualOptions), { transactionManager: tm }));
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
const { columnQuotesSymbol: cqs } = this.qb;
|
|
229
|
+
let deleteQuery = `delete from ${cqs}${tableName}${cqs} where `;
|
|
230
|
+
let runDeleteQuery = false;
|
|
231
|
+
let insertQuery = `insert into ${cqs}${tableName}${cqs} (${cqs}${currentEntityColumn}${cqs}, ${cqs}${counterpartColumn}${cqs}) values `;
|
|
232
|
+
let runInsertQuery = false;
|
|
233
|
+
items.forEach(item => {
|
|
234
|
+
const { deleted, value } = item;
|
|
235
|
+
if (deleted) {
|
|
236
|
+
if (runDeleteQuery) {
|
|
237
|
+
deleteQuery += ' or ';
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
runDeleteQuery = true;
|
|
241
|
+
}
|
|
242
|
+
deleteQuery += `(${cqs}${currentEntityColumn}${cqs} = ${id} and ${cqs}${counterpartColumn}${cqs} = ${value})`;
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (runInsertQuery) {
|
|
246
|
+
insertQuery += ', ';
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
runInsertQuery = true;
|
|
250
|
+
}
|
|
251
|
+
insertQuery += `(${id}, ${value})`;
|
|
252
|
+
});
|
|
253
|
+
if (runDeleteQuery) {
|
|
254
|
+
yield transactionManager.query(deleteQuery);
|
|
255
|
+
}
|
|
256
|
+
if (runInsertQuery) {
|
|
257
|
+
yield transactionManager.query(`${insertQuery} on conflict do nothing`);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
save(data, transactionManager) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
if (transactionManager) {
|
|
264
|
+
return (yield transactionManager.save(this.repository.target, data));
|
|
265
|
+
}
|
|
266
|
+
return this.repository.save(data);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
update(data, options) {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
const { filters, forceTransaction, returnData, transactionManager } = options;
|
|
272
|
+
if (!transactionManager && forceTransaction) {
|
|
273
|
+
return this.repository.manager.transaction(tm => {
|
|
274
|
+
return this.update(data, Object.assign(Object.assign({}, options), { transactionManager: tm }));
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const entityName = this.repository.metadata.name;
|
|
278
|
+
const tableName = this.repository.metadata.tableName;
|
|
279
|
+
const queryBuilder = this.getRepository(transactionManager)
|
|
280
|
+
.createQueryBuilder(entityName)
|
|
281
|
+
.update()
|
|
282
|
+
.set(data);
|
|
283
|
+
const { where: parsedWhere, include } = this.qb.parseFilters(tableName, filters);
|
|
284
|
+
let where = {};
|
|
285
|
+
if (Object.keys(include).length) {
|
|
286
|
+
const findData = yield this.find({ filters, transactionManager });
|
|
287
|
+
const { field, value } = this.buildPrimaryKeyWhereClause(findData.items);
|
|
288
|
+
where[field] = value;
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
where = parsedWhere;
|
|
292
|
+
}
|
|
293
|
+
this.qb.buildQuery(queryBuilder, { where });
|
|
294
|
+
if (returnData) {
|
|
295
|
+
const result = yield queryBuilder.returning('*').execute();
|
|
296
|
+
return { items: result.raw };
|
|
297
|
+
}
|
|
298
|
+
const result = yield queryBuilder.execute();
|
|
299
|
+
return { count: typeof result.affected === 'number' ? result.affected : undefined };
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
exports.RDBEntityService = RDBEntityService;
|
|
304
|
+
//# sourceMappingURL=rdb.entity.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rdb.entity.service.js","sourceRoot":"","sources":["../../src/entityService/rdb.entity.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCASsB;AAKtB,qFAS0C;AAS1C,MAAa,gBAA+C,SAAQ,+BAAgC;IAGlG,YAEY,EAA0B,EAE1B,UAA8B,EAC9B,MAAoB;;QAE9B,KAAK,EAAE,CAAC;QALE,OAAE,GAAF,EAAE,CAAwB;QAE1B,eAAU,GAAV,UAAU,CAAoB;QAC9B,WAAM,GAAN,MAAM,CAAc;QAG9B,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,WAAW,GAAa,EAAE,CAAC;QACjC,KAAK,MAAM,UAAU,IAAI,OAAO,EAAE;YAChC,IAAI,MAAA,OAAO,CAAC,UAAU,CAAC,0CAAE,OAAO,EAAE;gBAChC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aAC9B;SACF;QACD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAES,0BAA0B,CAAC,IAAc;QACjD,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;QAC7C,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;QACvC,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC;QAChD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,E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AS,EAAE,OAAO,CAAC,CAAC;YACjF,IAAI,KAAK,GAA0C,EAAE,CAAC;YACtD,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE;gBAC/B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC,CAAC;gBAClE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACzE,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;aACtB;iBAAM;gBACL,KAAK,GAAG,WAAW,CAAC;aACrB;YACD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAS,YAAY,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YACpD,IAAI,UAAU,EAAE;gBACd,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;gBAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;aAC9B;YACD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,CAAC;YAC5C,OAAO,EAAE,KAAK,EAAE,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;QACtF,CAAC;KAAA;CACF;AA1TD,4CA0TC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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("./common/definitions"), exports);
|
|
18
|
+
__exportStar(require("./entityService"), exports);
|
|
19
|
+
__exportStar(require("./module"), exports);
|
|
20
|
+
__exportStar(require("./repository"), exports);
|
|
21
|
+
__exportStar(require("./sqlQueryBuilder"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,kDAAgC;AAChC,2CAAyB;AACzB,+CAA6B;AAC7B,oDAAkC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./rdb.module.definitions"), exports);
|
|
18
|
+
__exportStar(require("./rdb.module"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/module/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,+CAA6B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ModuleMetadata } from '@nestjs/common';
|
|
2
|
+
import { GenericObject } from '@node-c/core';
|
|
3
|
+
export interface RDBModuleOptions {
|
|
4
|
+
connectionName: string;
|
|
5
|
+
exports?: ModuleMetadata['exports'];
|
|
6
|
+
folderData: GenericObject<unknown>;
|
|
7
|
+
imports?: {
|
|
8
|
+
atEnd?: ModuleMetadata['imports'];
|
|
9
|
+
postORM?: ModuleMetadata['imports'];
|
|
10
|
+
preORM?: ModuleMetadata['imports'];
|
|
11
|
+
};
|
|
12
|
+
moduleClass: unknown;
|
|
13
|
+
moduleName: string;
|
|
14
|
+
providers?: ModuleMetadata['providers'];
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rdb.module.definitions.js","sourceRoot":"","sources":["../../src/module/rdb.module.definitions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RDBModule = void 0;
|
|
4
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
5
|
+
const core_1 = require("@node-c/core");
|
|
6
|
+
const sqlQueryBuilder_1 = require("../sqlQueryBuilder");
|
|
7
|
+
class RDBModule {
|
|
8
|
+
static register(options) {
|
|
9
|
+
const { connectionName, folderData, imports: additionalImports, moduleClass, moduleName } = options;
|
|
10
|
+
const { atEnd: importsAtEnd, postORM: importsPostORM, preORM: importsPreORM } = additionalImports || {};
|
|
11
|
+
const { entities, modules } = (0, core_1.loadDynamicModules)(folderData);
|
|
12
|
+
return {
|
|
13
|
+
global: true,
|
|
14
|
+
module: moduleClass,
|
|
15
|
+
imports: [
|
|
16
|
+
...(importsPreORM || []),
|
|
17
|
+
typeorm_1.TypeOrmModule.forRootAsync({
|
|
18
|
+
useFactory: (configProvider) => {
|
|
19
|
+
const persistanceConfig = configProvider.config.persistance;
|
|
20
|
+
const { database, host, password, port, type, user } = persistanceConfig[moduleName];
|
|
21
|
+
return {
|
|
22
|
+
database,
|
|
23
|
+
entities: entities,
|
|
24
|
+
host,
|
|
25
|
+
name: connectionName,
|
|
26
|
+
password,
|
|
27
|
+
port,
|
|
28
|
+
type,
|
|
29
|
+
username: user
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
inject: [core_1.ConfigProviderService]
|
|
33
|
+
}),
|
|
34
|
+
sqlQueryBuilder_1.SQLQueryBuilderModule.register({ persistanceModuleName: moduleName }),
|
|
35
|
+
...(importsPostORM || []),
|
|
36
|
+
...(modules || []),
|
|
37
|
+
...(importsAtEnd || [])
|
|
38
|
+
],
|
|
39
|
+
providers: [...(options.providers || [])],
|
|
40
|
+
exports: [...(modules || []), ...(options.exports || [])]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.RDBModule = RDBModule;
|
|
45
|
+
//# sourceMappingURL=rdb.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rdb.module.js","sourceRoot":"","sources":["../../src/module/rdb.module.ts"],"names":[],"mappings":";;;AACA,6CAAsE;AAGtE,uCAAkG;AAIlG,wDAA2D;AAI3D,MAAa,SAAS;IACpB,MAAM,CAAC,QAAQ,CAAC,OAAyB;QACvC,MAA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