@qrvey/data-persistence 0.0.3-Rev-2 → 0.0.3-Rev-1-ds-support-array
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/services/crudFactory.service.js +5 -4
- package/dist/cjs/services/crudFactory.service.js.map +1 -1
- package/dist/types/index.d.ts +26 -26
- package/package.json +9 -9
- package/dist/cjs/helpers/queryHelpers.js +0 -14
- package/dist/cjs/helpers/queryHelpers.js.map +0 -1
- package/dist/cjs/helpers/tableHelper.js +0 -25
- package/dist/cjs/helpers/tableHelper.js.map +0 -1
- package/dist/cjs/interfaces/queryBuilder.interface.js +0 -3
- package/dist/cjs/interfaces/queryBuilder.interface.js.map +0 -1
- package/dist/cjs/interfaces/queryBuilderCondition.interface.js +0 -3
- package/dist/cjs/interfaces/queryBuilderCondition.interface.js.map +0 -1
- package/dist/cjs/services/cruds/dynamodb/dynamoDbClient.service.js +0 -100
- package/dist/cjs/services/cruds/dynamodb/dynamoDbClient.service.js.map +0 -1
- package/dist/cjs/services/cruds/dynamodb/dynamoDbCrud.service.js +0 -200
- package/dist/cjs/services/cruds/dynamodb/dynamoDbCrud.service.js.map +0 -1
- package/dist/cjs/services/cruds/dynamodb/queryBuilder.service.js +0 -71
- package/dist/cjs/services/cruds/dynamodb/queryBuilder.service.js.map +0 -1
- package/dist/cjs/services/cruds/dynamodb/queryBuilderCondition.service.js +0 -156
- package/dist/cjs/services/cruds/dynamodb/queryBuilderCondition.service.js.map +0 -1
- package/dist/cjs/services/cruds/index.js +0 -19
- package/dist/cjs/services/cruds/index.js.map +0 -1
- package/dist/cjs/services/cruds/postgresql/connection.service.js +0 -40
- package/dist/cjs/services/cruds/postgresql/connection.service.js.map +0 -1
- package/dist/cjs/services/cruds/postgresql/postgreSqlClient.service.js +0 -172
- package/dist/cjs/services/cruds/postgresql/postgreSqlClient.service.js.map +0 -1
- package/dist/cjs/services/cruds/postgresql/postgreSqlCrud.service.js +0 -90
- package/dist/cjs/services/cruds/postgresql/postgreSqlCrud.service.js.map +0 -1
- package/dist/cjs/services/cruds/postgresql/query.service.js +0 -31
- package/dist/cjs/services/cruds/postgresql/query.service.js.map +0 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CrudFactory = void 0;
|
|
4
|
-
const cruds_1 = require("./cruds");
|
|
5
4
|
class CrudFactory {
|
|
6
5
|
static databaseClientService(crudSchema) {
|
|
7
6
|
var _a;
|
|
8
7
|
const isMultiPlatformMode = ((_a = process.env.PLATFORM_TYPE) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'container';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const DatabaseCrudServiceImport = isMultiPlatformMode
|
|
9
|
+
? require('./cruds').PostgreSqlCrudService
|
|
10
|
+
: require('./cruds').DynamoDbCrudService;
|
|
11
|
+
const DatabaseCrudService = DatabaseCrudServiceImport;
|
|
12
|
+
return new DatabaseCrudService(crudSchema);
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
exports.CrudFactory = CrudFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crudFactory.service.js","sourceRoot":"","sources":["../../../src/services/crudFactory.service.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"crudFactory.service.js","sourceRoot":"","sources":["../../../src/services/crudFactory.service.ts"],"names":[],"mappings":";;;AAGA,MAAa,WAAW;IACpB,MAAM,CAAC,qBAAqB,CACxB,UAA6B;;QAE7B,MAAM,mBAAmB,GACrB,CAAA,MAAA,OAAO,CAAC,GAAG,CAAC,aAAa,0CAAE,WAAW,EAAE,MAAK,WAAW,CAAC;QAE7D,MAAM,yBAAyB,GAAG,mBAAmB;YACjD,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,qBAAqB;YAC1C,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,mBAAmB,CAAC;QAE7C,MAAM,mBAAmB,GAAG,yBAER,CAAC;QAErB,OAAO,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;CACJ;AAjBD,kCAiBC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
type FilterInput = string | IFilter[] | ICompoundFilter[] | ICompoundFilter;
|
|
2
|
+
|
|
3
|
+
declare enum SORT_DIRECTIONS {
|
|
4
|
+
ASC = "ASC",
|
|
5
|
+
DESC = "DESC"
|
|
6
|
+
}
|
|
7
|
+
declare enum FILTER_LOGIC_OPERATORS {
|
|
8
|
+
AND = "AND",
|
|
9
|
+
OR = "OR"
|
|
10
|
+
}
|
|
11
|
+
declare enum AGGREGATE_FUNCTIONS {
|
|
12
|
+
COUNT = "COUNT"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type SortDirection = keyof typeof SORT_DIRECTIONS;
|
|
16
|
+
|
|
17
|
+
declare const VALID_FILTER_LOGIC_OPERATORS: FILTER_LOGIC_OPERATORS[];
|
|
18
|
+
type FilterLogicOperator = (typeof VALID_FILTER_LOGIC_OPERATORS)[number];
|
|
19
|
+
|
|
20
|
+
type AggregateFunction = keyof typeof AGGREGATE_FUNCTIONS;
|
|
21
|
+
|
|
1
22
|
interface IFilter {
|
|
2
23
|
attribute: string;
|
|
3
24
|
operator?: string;
|
|
@@ -20,6 +41,11 @@ interface IFindPagination {
|
|
|
20
41
|
from?: any;
|
|
21
42
|
}
|
|
22
43
|
|
|
44
|
+
interface ISorting {
|
|
45
|
+
column: string;
|
|
46
|
+
direction?: SortDirection;
|
|
47
|
+
}
|
|
48
|
+
|
|
23
49
|
interface IFindOptions {
|
|
24
50
|
fields?: string[];
|
|
25
51
|
filters?: IFilter[] | ICompoundFilter;
|
|
@@ -53,20 +79,6 @@ interface ICrudService<T> {
|
|
|
53
79
|
runQuery(queryCommand: any): Promise<any>;
|
|
54
80
|
}
|
|
55
81
|
|
|
56
|
-
declare enum SORT_DIRECTIONS {
|
|
57
|
-
ASC = "ASC",
|
|
58
|
-
DESC = "DESC"
|
|
59
|
-
}
|
|
60
|
-
declare enum FILTER_LOGIC_OPERATORS {
|
|
61
|
-
AND = "AND",
|
|
62
|
-
OR = "OR"
|
|
63
|
-
}
|
|
64
|
-
declare enum AGGREGATE_FUNCTIONS {
|
|
65
|
-
COUNT = "COUNT"
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
type SortDirection = keyof typeof SORT_DIRECTIONS;
|
|
69
|
-
|
|
70
82
|
interface ITableName {
|
|
71
83
|
name: string;
|
|
72
84
|
alias?: string;
|
|
@@ -80,18 +92,6 @@ interface ITableColumns {
|
|
|
80
92
|
};
|
|
81
93
|
}
|
|
82
94
|
|
|
83
|
-
type FilterInput = string | IFilter[] | ICompoundFilter[] | ICompoundFilter;
|
|
84
|
-
|
|
85
|
-
declare const VALID_FILTER_LOGIC_OPERATORS: FILTER_LOGIC_OPERATORS[];
|
|
86
|
-
type FilterLogicOperator = (typeof VALID_FILTER_LOGIC_OPERATORS)[number];
|
|
87
|
-
|
|
88
|
-
type AggregateFunction = keyof typeof AGGREGATE_FUNCTIONS;
|
|
89
|
-
|
|
90
|
-
interface ISorting {
|
|
91
|
-
column: string;
|
|
92
|
-
direction?: SortDirection;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
95
|
declare class CrudSchema {
|
|
96
96
|
static table: string | ITableName;
|
|
97
97
|
static columns: ITableColumns;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@qrvey/data-persistence",
|
|
3
3
|
"types": "dist/types/index.d.ts",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
|
-
"version": "0.0.3-Rev-
|
|
5
|
+
"version": "0.0.3-Rev-1-ds-support-array",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
@@ -50,16 +50,16 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@types/jest": "
|
|
54
|
-
"@types/pg": "
|
|
55
|
-
"@types/pg-format": "
|
|
56
|
-
"auto-version-js": "
|
|
53
|
+
"@types/jest": "29.5.5",
|
|
54
|
+
"@types/pg": "8.11.4",
|
|
55
|
+
"@types/pg-format": "1.0.5",
|
|
56
|
+
"auto-version-js": "0.3.10",
|
|
57
57
|
"eslint-config-custom": "*",
|
|
58
|
-
"jest": "
|
|
59
|
-
"ts-jest": "
|
|
58
|
+
"jest": "29.7.0",
|
|
59
|
+
"ts-jest": "29.1.1",
|
|
60
60
|
"tsconfig": "*",
|
|
61
|
-
"tsup": "
|
|
62
|
-
"typescript": "
|
|
61
|
+
"tsup": "7.2.0",
|
|
62
|
+
"typescript": "5.2.2"
|
|
63
63
|
},
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildAggFunctionAlias = exports.METHOD_TO_QUERY = void 0;
|
|
4
|
-
var METHOD_TO_QUERY;
|
|
5
|
-
(function (METHOD_TO_QUERY) {
|
|
6
|
-
METHOD_TO_QUERY["where"] = "where";
|
|
7
|
-
METHOD_TO_QUERY["filter"] = "filter";
|
|
8
|
-
METHOD_TO_QUERY["update"] = "update";
|
|
9
|
-
})(METHOD_TO_QUERY || (exports.METHOD_TO_QUERY = METHOD_TO_QUERY = {}));
|
|
10
|
-
function buildAggFunctionAlias(aggregateFunction) {
|
|
11
|
-
return `AGG_FN_${aggregateFunction}`;
|
|
12
|
-
}
|
|
13
|
-
exports.buildAggFunctionAlias = buildAggFunctionAlias;
|
|
14
|
-
//# sourceMappingURL=queryHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queryHelpers.js","sourceRoot":"","sources":["../../../src/helpers/queryHelpers.ts"],"names":[],"mappings":";;;AAEA,IAAY,eAIX;AAJD,WAAY,eAAe;IACvB,kCAAe,CAAA;IACf,oCAAiB,CAAA;IACjB,oCAAiB,CAAA;AACrB,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B;AAED,SAAgB,qBAAqB,CACjC,iBAAoC;IAEpC,OAAO,UAAU,iBAAiB,EAAE,CAAC;AACzC,CAAC;AAJD,sDAIC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPrimaryKeyColumns = exports.getTableName = exports.findIdColumnName = exports.getTableColumnNames = void 0;
|
|
4
|
-
function getTableColumnNames(columns) {
|
|
5
|
-
return Object.keys(columns);
|
|
6
|
-
}
|
|
7
|
-
exports.getTableColumnNames = getTableColumnNames;
|
|
8
|
-
function findIdColumnName(columns) {
|
|
9
|
-
return getTableColumnNames(columns).find((columnName) => columns[columnName].columnId === true);
|
|
10
|
-
}
|
|
11
|
-
exports.findIdColumnName = findIdColumnName;
|
|
12
|
-
function getTableName(table, property = 'name') {
|
|
13
|
-
if (!table)
|
|
14
|
-
throw new Error('missing table property');
|
|
15
|
-
if (typeof table === 'string')
|
|
16
|
-
return table;
|
|
17
|
-
const { name, alias } = table;
|
|
18
|
-
return property === 'alias' && alias ? alias : name;
|
|
19
|
-
}
|
|
20
|
-
exports.getTableName = getTableName;
|
|
21
|
-
function getPrimaryKeyColumns(columns) {
|
|
22
|
-
return getTableColumnNames(columns).filter((columnName) => columns[columnName].primary === true);
|
|
23
|
-
}
|
|
24
|
-
exports.getPrimaryKeyColumns = getPrimaryKeyColumns;
|
|
25
|
-
//# sourceMappingURL=tableHelper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tableHelper.js","sourceRoot":"","sources":["../../../src/helpers/tableHelper.ts"],"names":[],"mappings":";;;AAEA,SAAgB,mBAAmB,CAAC,OAAsB;IACtD,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC;AAFD,kDAEC;AAED,SAAgB,gBAAgB,CAAC,OAAsB;IACnD,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC,IAAI,CACpC,CAAC,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,KAAK,IAAI,CACxD,CAAC;AACN,CAAC;AAJD,4CAIC;AAED,SAAgB,YAAY,CACxB,KAA0B,EAC1B,QAAQ,GAAG,MAAM;IAEjB,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAEtD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE5C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAC9B,OAAO,QAAQ,KAAK,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACxD,CAAC;AAVD,oCAUC;AAED,SAAgB,oBAAoB,CAAC,OAAsB;IACvD,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC,MAAM,CACtC,CAAC,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,KAAK,IAAI,CACvD,CAAC;AACN,CAAC;AAJD,oDAIC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queryBuilder.interface.js","sourceRoot":"","sources":["../../../src/interfaces/queryBuilder.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queryBuilderCondition.interface.js","sourceRoot":"","sources":["../../../src/interfaces/queryBuilderCondition.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
4
|
-
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
5
|
-
const AWS_REGION = process.env.AWS_DEFAULT_REGION;
|
|
6
|
-
/**
|
|
7
|
-
* Ref:
|
|
8
|
-
* - https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html
|
|
9
|
-
* - https://www.fernandomc.com/posts/eight-examples-of-fetching-data-from-dynamodb-with-node/
|
|
10
|
-
*/
|
|
11
|
-
class DynamoDbClientService {
|
|
12
|
-
constructor(tableName) {
|
|
13
|
-
if (!tableName)
|
|
14
|
-
throw new Error('The "tableName" is required to use a DynamoDbClientService.');
|
|
15
|
-
this.tableName = tableName;
|
|
16
|
-
const client = new client_dynamodb_1.DynamoDBClient({ region: AWS_REGION });
|
|
17
|
-
this.dynamoDBClient = lib_dynamodb_1.DynamoDBDocumentClient.from(client, {
|
|
18
|
-
marshallOptions: {
|
|
19
|
-
removeUndefinedValues: true,
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Get an item by key
|
|
25
|
-
* @param {Object} keyObject - Ex: { jobId: 1234 }
|
|
26
|
-
* @param {GetCommandInput} options
|
|
27
|
-
*/
|
|
28
|
-
async getByKey(
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
keyObject, options = {}) {
|
|
31
|
-
const params = Object.assign({ TableName: this.tableName, Key: keyObject }, options);
|
|
32
|
-
const result = await this.dynamoDBClient.send(new lib_dynamodb_1.GetCommand(params));
|
|
33
|
-
return result.Item;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Query a table
|
|
37
|
-
* @param {QueryCommandInput} options
|
|
38
|
-
*/
|
|
39
|
-
async query(options = {}) {
|
|
40
|
-
const params = Object.assign({ TableName: this.tableName }, options);
|
|
41
|
-
const result = await this.dynamoDBClient.send(new lib_dynamodb_1.QueryCommand(params));
|
|
42
|
-
if (result.$metadata)
|
|
43
|
-
delete result.$metadata;
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Scan a table
|
|
48
|
-
* @param {ScanInput} options
|
|
49
|
-
*/
|
|
50
|
-
async scan(input) {
|
|
51
|
-
const params = Object.assign(Object.assign({}, input), { TableName: this.tableName });
|
|
52
|
-
const command = new lib_dynamodb_1.ScanCommand(params);
|
|
53
|
-
const response = await this.dynamoDBClient.send(command);
|
|
54
|
-
if (response.$metadata)
|
|
55
|
-
delete response.$metadata;
|
|
56
|
-
return response;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Create/Replace a item object
|
|
60
|
-
* To take care:
|
|
61
|
-
* - https://stackoverflow.com/questions/43667229/difference-between-dynamodb-putitem-vs-updateitem
|
|
62
|
-
* @param {Object} input
|
|
63
|
-
*/
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
-
async put(input) {
|
|
66
|
-
const params = {
|
|
67
|
-
TableName: this.tableName,
|
|
68
|
-
Item: input,
|
|
69
|
-
ReturnValues: 'NONE',
|
|
70
|
-
};
|
|
71
|
-
return await this.dynamoDBClient.send(new lib_dynamodb_1.PutCommand(params));
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Update a item object
|
|
75
|
-
* To take care:
|
|
76
|
-
* - https://stackoverflow.com/questions/43667229/difference-between-dynamodb-putitem-vs-updateitem
|
|
77
|
-
* @param {Object} keyObject - Ex: { jobId: 1234 }
|
|
78
|
-
* @param {UpdateCommandInput} updateObject
|
|
79
|
-
*/
|
|
80
|
-
async update(
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
|
-
keyObject, options = {}) {
|
|
83
|
-
const params = Object.assign({ TableName: this.tableName, Key: keyObject, ReturnValues: 'NONE' }, options);
|
|
84
|
-
return await this.dynamoDBClient.send(new lib_dynamodb_1.UpdateCommand(params));
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Delete/Remove an item object
|
|
88
|
-
*/
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
90
|
-
async remove(keyObject) {
|
|
91
|
-
const params = {
|
|
92
|
-
TableName: this.tableName,
|
|
93
|
-
Key: keyObject,
|
|
94
|
-
ReturnValues: 'NONE',
|
|
95
|
-
};
|
|
96
|
-
return await this.dynamoDBClient.send(new lib_dynamodb_1.DeleteCommand(params));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
exports.default = DynamoDbClientService;
|
|
100
|
-
//# sourceMappingURL=dynamoDbClient.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dynamoDbClient.service.js","sourceRoot":"","sources":["../../../../../src/services/cruds/dynamodb/dynamoDbClient.service.ts"],"names":[],"mappings":";;AAAA,8DAA0D;AAC1D,wDAe+B;AAE/B,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;AAElD;;;;GAIG;AACH,MAAqB,qBAAqB;IAItC,YAAY,SAAiB;QACzB,IAAI,CAAC,SAAS;YACV,MAAM,IAAI,KAAK,CACX,6DAA6D,CAChE,CAAC;QACN,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,MAAM,MAAM,GAAG,IAAI,gCAAc,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,cAAc,GAAG,qCAAsB,CAAC,IAAI,CAAC,MAAM,EAAE;YACtD,eAAe,EAAE;gBACb,qBAAqB,EAAE,IAAI;aAC9B;SACJ,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,QAAQ;IACjB,8DAA8D;IAC9D,SAA8B,EAC9B,UAAoC,EAAE;QAEtC,MAAM,MAAM,mBACR,SAAS,EAAE,IAAI,CAAC,SAAS,EACzB,GAAG,EAAE,SAAS,IACX,OAAO,CACb,CAAC;QACF,MAAM,M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AC9B,UAAuC,EAAE;QAEzC,MAAM,MAAM,mBACR,SAAS,EAAE,IAAI,CAAC,SAAS,EACzB,GAAG,EAAE,SAAS,EACd,YAAY,EAAE,MAAM,IACjB,OAAO,CACb,CAAC;QACF,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,4BAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;IAED;;OAEG;IACH,8DAA8D;IACvD,KAAK,CAAC,MAAM,CAAC,SAA8B;QAC9C,MAAM,MAAM,GAAuB;YAC/B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,GAAG,EAAE,SAAS;YACd,YAAY,EAAE,MAAM;SACvB,CAAC;QACF,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,4BAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;CACJ;AA3HD,wCA2HC"}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DynamoDbCrudService = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
-
const q_id_generator_1 = require("q-id-generator");
|
|
9
|
-
const dynamoDbClient_service_1 = __importDefault(require("./dynamoDbClient.service"));
|
|
10
|
-
const queryBuilder_service_1 = __importDefault(require("./queryBuilder.service"));
|
|
11
|
-
const constants_1 = require("../../../utils/constants");
|
|
12
|
-
const tableHelper_1 = require("../../../helpers/tableHelper");
|
|
13
|
-
class DynamoDbCrudService {
|
|
14
|
-
constructor(tableSchema) {
|
|
15
|
-
this.tableSchema = tableSchema;
|
|
16
|
-
this.dynamoDbClientService = new dynamoDbClient_service_1.default(this.tableName);
|
|
17
|
-
}
|
|
18
|
-
get tableName() {
|
|
19
|
-
return (0, tableHelper_1.getTableName)(this.tableSchema.table);
|
|
20
|
-
}
|
|
21
|
-
get idColumnName() {
|
|
22
|
-
return (0, tableHelper_1.findIdColumnName)(this.tableSchema.columns);
|
|
23
|
-
}
|
|
24
|
-
get defaultPrimaryKeys() {
|
|
25
|
-
return (0, tableHelper_1.getPrimaryKeyColumns)(this.tableSchema.columns);
|
|
26
|
-
}
|
|
27
|
-
async create(entity) {
|
|
28
|
-
var _a;
|
|
29
|
-
let inputData = entity;
|
|
30
|
-
if (this.idColumnName) {
|
|
31
|
-
const idValue = ((_a = entity[this.idColumnName]) === null || _a === void 0 ? void 0 : _a.toString()) || (0, q_id_generator_1.getId)();
|
|
32
|
-
inputData = Object.assign(Object.assign({}, entity), { [this.idColumnName]: idValue });
|
|
33
|
-
}
|
|
34
|
-
await this.dynamoDbClientService.put(inputData);
|
|
35
|
-
return inputData;
|
|
36
|
-
}
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
|
|
38
|
-
runQuery(queryCommand) {
|
|
39
|
-
throw new Error('Method not implemented.');
|
|
40
|
-
}
|
|
41
|
-
find(options = {}) {
|
|
42
|
-
var _a, _b, _c, _d;
|
|
43
|
-
const query = new queryBuilder_service_1.default(options.useScan);
|
|
44
|
-
if ((_a = options.index) === null || _a === void 0 ? void 0 : _a.indexName)
|
|
45
|
-
query.usingIndex((_b = options.index) === null || _b === void 0 ? void 0 : _b.indexName);
|
|
46
|
-
this.applySorting(query, options.sorting, (_c = options.index) === null || _c === void 0 ? void 0 : _c.indexName);
|
|
47
|
-
this.applyPagination(query, options.pagination);
|
|
48
|
-
if (options.consistentRead)
|
|
49
|
-
query.consistentRead(options.consistentRead);
|
|
50
|
-
if (options.fields)
|
|
51
|
-
query.projection(options.fields);
|
|
52
|
-
this.applyFilters(query, options);
|
|
53
|
-
return this.fetchResults(query.get(), (_d = options.pagination) === null || _d === void 0 ? void 0 : _d.limit, options.useScan).then((res) => {
|
|
54
|
-
var _a, _b;
|
|
55
|
-
const pagination = {};
|
|
56
|
-
if (res.lastEvaluatedKey)
|
|
57
|
-
pagination.from = res.lastEvaluatedKey;
|
|
58
|
-
if ((_a = options.pagination) === null || _a === void 0 ? void 0 : _a.limit)
|
|
59
|
-
pagination.limit = (_b = options.pagination) === null || _b === void 0 ? void 0 : _b.limit;
|
|
60
|
-
return {
|
|
61
|
-
items: res.items,
|
|
62
|
-
pagination,
|
|
63
|
-
count: res.items.length,
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
async fetchResults(command, limit = 100, useScan = false) {
|
|
68
|
-
var _a, _b, _c, _d, _e;
|
|
69
|
-
let results = [];
|
|
70
|
-
let LastEvaluatedKey = {};
|
|
71
|
-
do {
|
|
72
|
-
if (this.isNotEmptyObject(LastEvaluatedKey))
|
|
73
|
-
command.ExclusiveStartKey = LastEvaluatedKey;
|
|
74
|
-
const result = await (useScan
|
|
75
|
-
? this.dynamoDbClientService.scan(command)
|
|
76
|
-
: this.dynamoDbClientService.query(command));
|
|
77
|
-
command.Limit = ((_a = command.Limit) !== null && _a !== void 0 ? _a : 0) - ((_c = (_b = result.Items) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0);
|
|
78
|
-
const rows = (_d = result.Items) !== null && _d !== void 0 ? _d : [];
|
|
79
|
-
results = [...results, ...rows];
|
|
80
|
-
LastEvaluatedKey = (_e = result.LastEvaluatedKey) !== null && _e !== void 0 ? _e : {};
|
|
81
|
-
} while (results.length < limit &&
|
|
82
|
-
this.isNotEmptyObject(LastEvaluatedKey));
|
|
83
|
-
const lastEvaluatedKey = this.isNotEmptyObject(LastEvaluatedKey)
|
|
84
|
-
? this.encryptPaginationKey(LastEvaluatedKey)
|
|
85
|
-
: null;
|
|
86
|
-
return { items: results, lastEvaluatedKey };
|
|
87
|
-
}
|
|
88
|
-
applyPagination(query, pagination) {
|
|
89
|
-
if (pagination === null || pagination === void 0 ? void 0 : pagination.limit)
|
|
90
|
-
query.limit(pagination.limit);
|
|
91
|
-
if (pagination === null || pagination === void 0 ? void 0 : pagination.from)
|
|
92
|
-
query.startKey(this.decryptPaginationKey(pagination.from));
|
|
93
|
-
}
|
|
94
|
-
async findAll(options = {}, allResults = []) {
|
|
95
|
-
const { items, pagination } = await this.find(options);
|
|
96
|
-
allResults.push(...items);
|
|
97
|
-
if (pagination === null || pagination === void 0 ? void 0 : pagination.from)
|
|
98
|
-
await this.findAll(Object.assign(Object.assign({}, options), { pagination }), allResults);
|
|
99
|
-
return {
|
|
100
|
-
items: allResults,
|
|
101
|
-
pagination: null,
|
|
102
|
-
count: allResults.length,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
async findCount(options = {}) {
|
|
106
|
-
const { items } = await this.find(options);
|
|
107
|
-
return items.length;
|
|
108
|
-
}
|
|
109
|
-
async findItem(options) {
|
|
110
|
-
var _a, _b, _c;
|
|
111
|
-
const query = new queryBuilder_service_1.default();
|
|
112
|
-
if ((_a = options.index) === null || _a === void 0 ? void 0 : _a.indexName)
|
|
113
|
-
query.usingIndex((_b = options.index) === null || _b === void 0 ? void 0 : _b.indexName);
|
|
114
|
-
this.applyFilters(query, options);
|
|
115
|
-
if (options.fields)
|
|
116
|
-
query.projection(options.fields);
|
|
117
|
-
query.limit(1);
|
|
118
|
-
const command = query.get();
|
|
119
|
-
const result = await this.dynamoDbClientService.query(command);
|
|
120
|
-
if ((result === null || result === void 0 ? void 0 : result.Items) && ((_c = result.Items) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
121
|
-
return result.Items[0];
|
|
122
|
-
}
|
|
123
|
-
if (options.throwErrorIfNull)
|
|
124
|
-
throw new Error('NOT_FOUND');
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
applyWhereFilter(query, filter) {
|
|
128
|
-
var _a, _b;
|
|
129
|
-
const operator = constants_1.FILTER_OPERATOR_MAP[(_b = (_a = filter.operator) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : constants_1.DYNAMODB_OPERATORS.EQUAL];
|
|
130
|
-
query.where(filter.attribute)[operator](filter.value);
|
|
131
|
-
}
|
|
132
|
-
applyFilterFilter(query, filter) {
|
|
133
|
-
var _a, _b;
|
|
134
|
-
const operator = constants_1.FILTER_OPERATOR_MAP[(_b = (_a = filter.operator) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : constants_1.DYNAMODB_OPERATORS.EQUAL];
|
|
135
|
-
query.filter(filter.attribute)[operator](filter.value);
|
|
136
|
-
}
|
|
137
|
-
applyFilters(query, options) {
|
|
138
|
-
var _a;
|
|
139
|
-
if (Array.isArray(options.filters)) {
|
|
140
|
-
const queryIndexColumns = ((_a = options.index) === null || _a === void 0 ? void 0 : _a.columns) || [];
|
|
141
|
-
const defaultWhereProperties = this.defaultPrimaryKeys;
|
|
142
|
-
const whereProperties = (queryIndexColumns === null || queryIndexColumns === void 0 ? void 0 : queryIndexColumns.length)
|
|
143
|
-
? queryIndexColumns
|
|
144
|
-
: defaultWhereProperties;
|
|
145
|
-
options.filters.forEach((filter) => {
|
|
146
|
-
const isWhereProperty = whereProperties.includes(filter.attribute) &&
|
|
147
|
-
!filter.omitPrimary;
|
|
148
|
-
isWhereProperty && !options.useScan
|
|
149
|
-
? this.applyWhereFilter(query, filter)
|
|
150
|
-
: this.applyFilterFilter(query, filter);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
applySorting(query, sorting, sortIndex) {
|
|
155
|
-
if (sorting === null || sorting === void 0 ? void 0 : sorting.length) {
|
|
156
|
-
if (sortIndex)
|
|
157
|
-
query.usingIndex(sortIndex);
|
|
158
|
-
if (sorting[0].direction === 'DESC') {
|
|
159
|
-
query.descending();
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
query.ascending();
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
isNotEmptyObject(obj) {
|
|
167
|
-
return (obj !== null &&
|
|
168
|
-
typeof obj === 'object' &&
|
|
169
|
-
Object.keys(obj).length > 0);
|
|
170
|
-
}
|
|
171
|
-
encryptPaginationKey(key) {
|
|
172
|
-
const jsonKey = JSON.stringify(key);
|
|
173
|
-
return Buffer.from(jsonKey).toString('base64');
|
|
174
|
-
}
|
|
175
|
-
decryptPaginationKey(encodedKey) {
|
|
176
|
-
const decodedKey = Buffer.from(encodedKey, 'base64').toString('utf-8');
|
|
177
|
-
return JSON.parse(decodedKey);
|
|
178
|
-
}
|
|
179
|
-
async update(filters, data, { replace = false }) {
|
|
180
|
-
const savedRecord = await this.findItem({
|
|
181
|
-
filters: filters,
|
|
182
|
-
});
|
|
183
|
-
if (replace) {
|
|
184
|
-
//delete all attributes of savedRecord except those that as marked as primary columns in the schema
|
|
185
|
-
}
|
|
186
|
-
const newData = Object.assign(Object.assign({}, savedRecord), data);
|
|
187
|
-
await this.dynamoDbClientService.put(newData);
|
|
188
|
-
return newData;
|
|
189
|
-
}
|
|
190
|
-
async remove(filters) {
|
|
191
|
-
const key = filters.reduce((obj, item) => {
|
|
192
|
-
const property = item.attribute;
|
|
193
|
-
obj[property] = item.value;
|
|
194
|
-
return obj;
|
|
195
|
-
}, {});
|
|
196
|
-
await this.dynamoDbClientService.remove(key);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
exports.DynamoDbCrudService = DynamoDbCrudService;
|
|
200
|
-
//# sourceMappingURL=dynamoDbCrud.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dynamoDbCrud.service.js","sourceRoot":"","sources":["../../../../../src/services/cruds/dynamodb/dynamoDbCrud.service.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAuD;AACvD,mDAAuC;AAEvC,sFAA6D;AAC7D,kFAAyD;AAEzD,wDAGkC;AASlC,8DAIsC;AAEtC,MAAa,mBAAmB;IAG5B,YAAoB,WAA8B;QAA9B,gBAAW,GAAX,WAAW,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C,UAAkB;QACnC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACvE,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,MAAM,CACR,OAAoC,EACpC,IAAgB,EAChB,EAAE,OAAO,GAAG,KAAK,EAAE;QAEnB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC;YACpC,OAAO,EAAE,OAAoB;SAChC,CAAC,CAAC;QAEH,IAAI,OAAO,EAAE,CAAC;YACV,mGAAmG;QACvG,CAAC;QAED,MAAM,OAAO,mCACN,WAAW,GACX,IAAI,CACV,CAAC;QAEF,MAAM,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9C,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAoC;QAC7C,MAAM,GAAG,GAAI,OAAqB,CAAC,MAAM,CAAC,CAAC,GAAQ,EAAE,IAAS,EAAE,EAAE;YAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC;YAChC,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;YAC3B,OAAO,GAAG,CAAC;QACf,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,MAAM,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjD,CAAC;CACJ;AAnPD,kDAmPC"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const queryBuilderCondition_service_1 = __importDefault(require("./queryBuilderCondition.service"));
|
|
7
|
-
const queryHelpers_1 = require("../../../helpers/queryHelpers");
|
|
8
|
-
class QueryBuilderService {
|
|
9
|
-
constructor(useScan = false) {
|
|
10
|
-
this.useScan = useScan;
|
|
11
|
-
this.command = {};
|
|
12
|
-
this.condition = new queryBuilderCondition_service_1.default(this);
|
|
13
|
-
}
|
|
14
|
-
get() {
|
|
15
|
-
const condition = this.condition.get();
|
|
16
|
-
return Object.assign(Object.assign({}, this.command), condition);
|
|
17
|
-
}
|
|
18
|
-
limit(num) {
|
|
19
|
-
this.command.Limit = num;
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
usingIndex(indexName) {
|
|
23
|
-
this.command.IndexName = indexName;
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
ascending() {
|
|
27
|
-
if (!this.useScan)
|
|
28
|
-
this.command.ScanIndexForward = true;
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
descending() {
|
|
32
|
-
if (!this.useScan)
|
|
33
|
-
this.command.ScanIndexForward = false;
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
startKey(lastEvaluatedKey) {
|
|
38
|
-
this.command.ExclusiveStartKey = lastEvaluatedKey;
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
projection(fields) {
|
|
42
|
-
const expression = [];
|
|
43
|
-
fields.forEach((field) => {
|
|
44
|
-
const key = this.condition.project(field);
|
|
45
|
-
expression.push(key);
|
|
46
|
-
});
|
|
47
|
-
this.command.ProjectionExpression = expression.join(',');
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
where(keyName) {
|
|
51
|
-
this.condition.setKey(keyName).from(queryHelpers_1.METHOD_TO_QUERY.where);
|
|
52
|
-
return this.condition;
|
|
53
|
-
}
|
|
54
|
-
filter(keyName) {
|
|
55
|
-
this.condition.setKey(keyName).from(queryHelpers_1.METHOD_TO_QUERY.filter);
|
|
56
|
-
return this.condition;
|
|
57
|
-
}
|
|
58
|
-
update(attribute) {
|
|
59
|
-
for (const [key, value] of Object.entries(attribute)) {
|
|
60
|
-
this.condition.setKey(key).from(queryHelpers_1.METHOD_TO_QUERY.update);
|
|
61
|
-
this.condition.eq(value);
|
|
62
|
-
}
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
consistentRead(consistentRead) {
|
|
66
|
-
this.command.ConsistentRead = consistentRead;
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.default = QueryBuilderService;
|
|
71
|
-
//# sourceMappingURL=queryBuilder.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queryBuilder.service.js","sourceRoot":"","sources":["../../../../../src/services/cruds/dynamodb/queryBuilder.service.ts"],"names":[],"mappings":";;;;;AAEA,oGAA2E;AAC3E,gEAAgE;AAGhE,MAAqB,mBAAmB;IAIpC,YAAoB,UAAU,KAAK;QAAf,YAAO,GAAP,OAAO,CAAQ;QAC/B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAElB,IAAI,CAAC,SAAS,GAAG,IAAI,uCAA4B,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC;IAED,GAAG;QACC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;QACvC,uCAAY,IAAI,CAAC,OAAO,GAAK,SAAS,EAAG;IAC7C,CAAC;IAED,KAAK,CAAC,GAAW;QACb,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,GAAG,CAAC;QACzB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,UAAU,CAAC,SAAiB;QACxB,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;QACnC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,SAAS;QACL,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;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C,CAAC,IAAI,CAAC,8BAAe,CAAC,MAAM,CAAC,CAAC;YACxD,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,cAAc,CAAC,cAAuB;QAClC,IAAI,CAAC,OAAO,CAAC,cAAc,GAAG,cAAc,CAAC;QAC7C,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAzED,sCAyEC"}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const queryHelpers_1 = require("../../../helpers/queryHelpers");
|
|
4
|
-
class QueryBuilderConditionService {
|
|
5
|
-
constructor(query) {
|
|
6
|
-
this.tempKey = '';
|
|
7
|
-
this.wheres = [];
|
|
8
|
-
this.filters = [];
|
|
9
|
-
this.updates = [];
|
|
10
|
-
this.attributeNames = {};
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
-
this.attributeValues = {};
|
|
13
|
-
this.query = query;
|
|
14
|
-
this.command = {};
|
|
15
|
-
}
|
|
16
|
-
get() {
|
|
17
|
-
this.build();
|
|
18
|
-
return this.command;
|
|
19
|
-
}
|
|
20
|
-
setKey(key) {
|
|
21
|
-
this.tempKey = key;
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
from(methodName) {
|
|
25
|
-
this.queryFrom = methodName;
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
eq(keyValue) {
|
|
29
|
-
const { key, value } = this.generateKeyValue(keyValue);
|
|
30
|
-
const expression = `${key} = ${value}`;
|
|
31
|
-
this.setExpression(expression);
|
|
32
|
-
return this.query;
|
|
33
|
-
}
|
|
34
|
-
notEq(keyValue) {
|
|
35
|
-
const { key, value } = this.generateKeyValue(keyValue);
|
|
36
|
-
const expression = `${key} <> ${value}`;
|
|
37
|
-
this.setExpression(expression);
|
|
38
|
-
return this.query;
|
|
39
|
-
}
|
|
40
|
-
contains(keyValue) {
|
|
41
|
-
const { key, value } = this.generateKeyValue(keyValue);
|
|
42
|
-
const expression = `contains(${key}, ${value})`;
|
|
43
|
-
this.setExpression(expression);
|
|
44
|
-
return this.query;
|
|
45
|
-
}
|
|
46
|
-
notContains(keyValue) {
|
|
47
|
-
const { key, value } = this.generateKeyValue(keyValue);
|
|
48
|
-
const expression = `NOT contains(${key}, ${value})`;
|
|
49
|
-
this.setExpression(expression);
|
|
50
|
-
return this.query;
|
|
51
|
-
}
|
|
52
|
-
in(keyValue) {
|
|
53
|
-
const keyValues = Array.isArray(keyValue) ? keyValue : [keyValue];
|
|
54
|
-
const { key, value } = this.generateKeyValue(keyValues);
|
|
55
|
-
const expression = `${key} IN (${value})`;
|
|
56
|
-
this.setExpression(expression);
|
|
57
|
-
return this.query;
|
|
58
|
-
}
|
|
59
|
-
beginsWith(keyValue) {
|
|
60
|
-
const { key, value } = this.generateKeyValue(keyValue);
|
|
61
|
-
const expression = `begins_with(${key}, ${value})`;
|
|
62
|
-
this.setExpression(expression);
|
|
63
|
-
return this.query;
|
|
64
|
-
}
|
|
65
|
-
project(keyValue) {
|
|
66
|
-
const key = `#${keyValue}`;
|
|
67
|
-
this.attributeNames[key] = keyValue;
|
|
68
|
-
return key;
|
|
69
|
-
}
|
|
70
|
-
gt(keyValue) {
|
|
71
|
-
const { key, value } = this.generateKeyValue(keyValue);
|
|
72
|
-
const expression = `${key} > ${value}`;
|
|
73
|
-
this.setExpression(expression);
|
|
74
|
-
return this.query;
|
|
75
|
-
}
|
|
76
|
-
gte(keyValue) {
|
|
77
|
-
const { key, value } = this.generateKeyValue(keyValue);
|
|
78
|
-
const expression = `${key} >= ${value}`;
|
|
79
|
-
this.setExpression(expression);
|
|
80
|
-
return this.query;
|
|
81
|
-
}
|
|
82
|
-
lte(keyValue) {
|
|
83
|
-
const { key, value } = this.generateKeyValue(keyValue);
|
|
84
|
-
const expression = `${key} <= ${value}`;
|
|
85
|
-
this.setExpression(expression);
|
|
86
|
-
return this.query;
|
|
87
|
-
}
|
|
88
|
-
lt(keyValue) {
|
|
89
|
-
const { key, value } = this.generateKeyValue(keyValue);
|
|
90
|
-
const expression = `${key} < ${value}`;
|
|
91
|
-
this.setExpression(expression);
|
|
92
|
-
return this.query;
|
|
93
|
-
}
|
|
94
|
-
attribute_exists(keyValue) {
|
|
95
|
-
const { key } = this.generateKeyValue(keyValue);
|
|
96
|
-
const expression = `attribute_exists(${key})`;
|
|
97
|
-
this.setExpression(expression);
|
|
98
|
-
return this.query;
|
|
99
|
-
}
|
|
100
|
-
attribute_not_exists(keyValue) {
|
|
101
|
-
const { key } = this.generateKeyValue(keyValue);
|
|
102
|
-
const expression = `attribute_not_exists(${key})`;
|
|
103
|
-
this.setExpression(expression);
|
|
104
|
-
return this.query;
|
|
105
|
-
}
|
|
106
|
-
setExpression(expression) {
|
|
107
|
-
switch (this.queryFrom) {
|
|
108
|
-
case queryHelpers_1.METHOD_TO_QUERY.filter:
|
|
109
|
-
this.filters.push(expression);
|
|
110
|
-
break;
|
|
111
|
-
case queryHelpers_1.METHOD_TO_QUERY.update:
|
|
112
|
-
this.updates.push(expression);
|
|
113
|
-
break;
|
|
114
|
-
default:
|
|
115
|
-
this.wheres.push(expression);
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
generateKeyValue(value) {
|
|
120
|
-
const keyExpression = `#${this.tempKey}1`;
|
|
121
|
-
this.attributeNames[keyExpression] = this.tempKey;
|
|
122
|
-
if (Array.isArray(value)) {
|
|
123
|
-
const valueExpressions = value.map((val, index) => {
|
|
124
|
-
const valueExpression = `:${this.tempKey}${index + 1}1`;
|
|
125
|
-
this.attributeValues[valueExpression] = val;
|
|
126
|
-
return valueExpression;
|
|
127
|
-
});
|
|
128
|
-
return { key: keyExpression, value: valueExpressions.join(', ') };
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
const valueExpression = `:${this.tempKey}1`;
|
|
132
|
-
this.attributeValues[valueExpression] = value;
|
|
133
|
-
return { key: keyExpression, value: valueExpression };
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
build() {
|
|
137
|
-
if (this.wheres.length > 0) {
|
|
138
|
-
const keyConditionExpression = this.wheres.join(' AND ');
|
|
139
|
-
this.command['KeyConditionExpression'] = keyConditionExpression;
|
|
140
|
-
}
|
|
141
|
-
if (this.filters.length > 0) {
|
|
142
|
-
const filterExpression = this.filters.join(' AND ');
|
|
143
|
-
this.command['FilterExpression'] = filterExpression;
|
|
144
|
-
}
|
|
145
|
-
if (this.updates.length > 0) {
|
|
146
|
-
const filterExpression = this.updates.join(', ');
|
|
147
|
-
this.command['UpdateExpression'] = `SET ${filterExpression}`;
|
|
148
|
-
}
|
|
149
|
-
if (Object.values(this.attributeNames).length > 0)
|
|
150
|
-
this.command['ExpressionAttributeNames'] = this.attributeNames;
|
|
151
|
-
if (Object.values(this.attributeValues).length > 0)
|
|
152
|
-
this.command['ExpressionAttributeValues'] = this.attributeValues;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
exports.default = QueryBuilderConditionService;
|
|
156
|
-
//# sourceMappingURL=queryBuilderCondition.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queryBuilderCondition.service.js","sourceRoot":"","sources":["../../../../../src/services/cruds/dynamodb/queryBuilderCondition.service.ts"],"names":[],"mappings":";;AAIA,gEAAgE;AAGhE,MAAqB,4BAA4B;IAoB7C,YAAY,KAAoB;QARxB,YAAO,GAAW,EAAE,CAAC;QACrB,WAAM,GAAa,EAAE,CAAC;QACtB,YAAO,GAAa,EAAE,CAAC;QACvB,YAAO,GAAa,EAAE,CAAC;QACvB,mBAAc,GAA2B,EAAE,CAAC;QACpD,8DAA8D;QACtD,oBAAe,GAAwB,EAAE,CAAC;QAG9C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,EA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AzLD,+CAyLC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
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("./dynamodb/dynamoDbCrud.service"), exports);
|
|
18
|
-
__exportStar(require("./postgresql/postgreSqlCrud.service"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/cruds/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kEAAgD;AAChD,sEAAoD"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const pg_1 = require("pg");
|
|
4
|
-
class ConnectionService {
|
|
5
|
-
constructor(usePool) {
|
|
6
|
-
this.pool = null;
|
|
7
|
-
if (usePool)
|
|
8
|
-
this.pool = new pg_1.Pool({ connectionString: this.connectionString });
|
|
9
|
-
}
|
|
10
|
-
get connectionString() {
|
|
11
|
-
return process.env.MULTIPLATFORM_PG_CONNECTION_STRING;
|
|
12
|
-
}
|
|
13
|
-
async getClient() {
|
|
14
|
-
if (this.pool) {
|
|
15
|
-
return this.pool.connect();
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
const client = new pg_1.Client({
|
|
19
|
-
connectionString: this.connectionString,
|
|
20
|
-
});
|
|
21
|
-
await client.connect();
|
|
22
|
-
return client;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
releaseClient(client) {
|
|
26
|
-
try {
|
|
27
|
-
if ('release' in client) {
|
|
28
|
-
client.release();
|
|
29
|
-
}
|
|
30
|
-
else if ('end' in client) {
|
|
31
|
-
client.end();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
catch (_a) {
|
|
35
|
-
// ignore any exception
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.default = ConnectionService;
|
|
40
|
-
//# sourceMappingURL=connection.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.service.js","sourceRoot":"","sources":["../../../../../src/services/cruds/postgresql/connection.service.ts"],"names":[],"mappings":";;AAAA,2BAA8C;AAE9C,MAAqB,iBAAiB;IAGlC,YAAY,OAAgB;QAFpB,SAAI,GAAgB,IAAI,CAAC;QAG7B,IAAI,OAAO;YACP,IAAI,CAAC,IAAI,GAAG,IAAI,SAAI,CAAC,EAAE,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,IAAI,gBAAgB;QAChB,OAAO,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,SAAS;QACX,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAC/B,CAAC;aAAM,CAAC;YACJ,MAAM,MAAM,GAAW,IAAI,WAAM,CAAC;gBAC9B,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;aAC1C,CAAC,CAAC;YACH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;YACvB,OAAO,MAAM,CAAC;QAClB,CAAC;IACL,CAAC;IAED,aAAa,CAAC,MAA2B;QACrC,IAAI,CAAC;YACD,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;gBACtB,MAAM,CAAC,OAAO,EAAE,CAAC;YACrB,CAAC;iBAAM,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;gBACzB,MAAM,CAAC,GAAG,EAAE,CAAC;YACjB,CAAC;QACL,CAAC;QAAC,WAAM,CAAC;YACL,uBAAuB;QAC3B,CAAC;IACL,CAAC;CACJ;AAnCD,oCAmCC"}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
/* eslint-disable no-console */
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
const pg_format_1 = __importDefault(require("pg-format"));
|
|
9
|
-
const query_service_1 = __importDefault(require("./query.service"));
|
|
10
|
-
const constants_1 = require("../../../utils/constants");
|
|
11
|
-
const tableHelper_1 = require("../../../helpers/tableHelper");
|
|
12
|
-
const queryHelpers_1 = require("../../../helpers/queryHelpers");
|
|
13
|
-
class PostgresqlClientService extends query_service_1.default {
|
|
14
|
-
constructor(tableSchema) {
|
|
15
|
-
const useConnectionPool = tableSchema.usePool || false;
|
|
16
|
-
super(useConnectionPool);
|
|
17
|
-
this.crudSchema = tableSchema;
|
|
18
|
-
}
|
|
19
|
-
get dbSchema() {
|
|
20
|
-
return this.crudSchema.schema || constants_1.DEFAULT_PG_SCHEMA;
|
|
21
|
-
}
|
|
22
|
-
get tableName() {
|
|
23
|
-
return ((0, tableHelper_1.getTableName)(this.crudSchema.table, 'alias') ||
|
|
24
|
-
(0, tableHelper_1.getTableName)(this.crudSchema.table));
|
|
25
|
-
}
|
|
26
|
-
getWildcardValue(operator, value) {
|
|
27
|
-
if (operator === constants_1.FilterOperator.CONTAINS ||
|
|
28
|
-
operator === constants_1.FilterOperator.NOT_CONTAINS) {
|
|
29
|
-
return '%' + value + '%';
|
|
30
|
-
}
|
|
31
|
-
else if (operator === constants_1.FilterOperator.STARTS_WITH) {
|
|
32
|
-
return value + '%';
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
buildClause(operator, attribute, value) {
|
|
39
|
-
const formattedValue = pg_format_1.default.literal(value);
|
|
40
|
-
operator = operator
|
|
41
|
-
? operator.toUpperCase()
|
|
42
|
-
: constants_1.FilterOperator.EQUAL;
|
|
43
|
-
const postgresOperator = constants_1.POSTGRES_FILTER_OPERATOR_MAP[operator];
|
|
44
|
-
if (!postgresOperator)
|
|
45
|
-
throw new Error(`Unsupported filter operator: ${operator}`);
|
|
46
|
-
if (operator === constants_1.FilterOperator.IN) {
|
|
47
|
-
const formattedValues = Array.isArray(value)
|
|
48
|
-
? value.map(pg_format_1.default.literal)
|
|
49
|
-
: [formattedValue];
|
|
50
|
-
return `${pg_format_1.default.ident(attribute)} ${postgresOperator} (${formattedValues.join(', ')})`;
|
|
51
|
-
}
|
|
52
|
-
const wildcardValue = this.getWildcardValue(operator, value);
|
|
53
|
-
return `${pg_format_1.default.ident(attribute)} ${postgresOperator} ${pg_format_1.default.literal(wildcardValue)}`;
|
|
54
|
-
}
|
|
55
|
-
buildFilterClause(filters, logicOperator) {
|
|
56
|
-
var _a;
|
|
57
|
-
if (Array.isArray(filters)) {
|
|
58
|
-
const filterClauses = filters.map((filter) => {
|
|
59
|
-
return this.buildClause(filter.operator, filter.attribute, filter.value);
|
|
60
|
-
});
|
|
61
|
-
return filterClauses.join(` ${logicOperator !== null && logicOperator !== void 0 ? logicOperator : constants_1.FILTER_LOGIC_OPERATORS.AND} `);
|
|
62
|
-
}
|
|
63
|
-
else if (filters.filters) {
|
|
64
|
-
const operator = (_a = filters.logicOperator) !== null && _a !== void 0 ? _a : constants_1.FILTER_LOGIC_OPERATORS.AND;
|
|
65
|
-
const simpleFilters = filters.filters;
|
|
66
|
-
const filterClauses = this.buildFilterClause(simpleFilters, operator);
|
|
67
|
-
return filterClauses;
|
|
68
|
-
}
|
|
69
|
-
return '';
|
|
70
|
-
}
|
|
71
|
-
formatOrderByItem(sort) {
|
|
72
|
-
return `${pg_format_1.default.ident(sort.column)} ${sort.direction || constants_1.SORT_DIRECTIONS.ASC}`;
|
|
73
|
-
}
|
|
74
|
-
buildOrderByClause(querySorting) {
|
|
75
|
-
try {
|
|
76
|
-
return querySorting.map(this.formatOrderByItem).join(', ');
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
return '';
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async createCommand(data) {
|
|
83
|
-
const keys = Object.keys(data);
|
|
84
|
-
const values = Object.values(data);
|
|
85
|
-
const query = (0, pg_format_1.default)(`INSERT INTO ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)} (%I) VALUES (%L) RETURNING *;`, keys, values);
|
|
86
|
-
return this.runQuery(query);
|
|
87
|
-
}
|
|
88
|
-
addFiltersToQuery(query, filters) {
|
|
89
|
-
if (filters)
|
|
90
|
-
query += ` WHERE ${this.buildFilterClause(filters)}`;
|
|
91
|
-
return query;
|
|
92
|
-
}
|
|
93
|
-
addOrderByToQuery(query, orderBy) {
|
|
94
|
-
if (orderBy)
|
|
95
|
-
query += ` ORDER BY ${this.buildOrderByClause(orderBy)}`;
|
|
96
|
-
return query;
|
|
97
|
-
}
|
|
98
|
-
addPaginationToQuery(query, pagination) {
|
|
99
|
-
if (pagination) {
|
|
100
|
-
const { limit, from } = pagination;
|
|
101
|
-
if (limit)
|
|
102
|
-
query += ` LIMIT ${limit}`;
|
|
103
|
-
if (from)
|
|
104
|
-
query += ` OFFSET ${from}`;
|
|
105
|
-
}
|
|
106
|
-
return query;
|
|
107
|
-
}
|
|
108
|
-
getSelectClause(aggregateFunction, fields = []) {
|
|
109
|
-
if (aggregateFunction)
|
|
110
|
-
return `CAST(${aggregateFunction}(1) AS INTEGER) AS "${(0, queryHelpers_1.buildAggFunctionAlias)(aggregateFunction)}"`;
|
|
111
|
-
if (!(fields === null || fields === void 0 ? void 0 : fields.length))
|
|
112
|
-
return '*';
|
|
113
|
-
return fields.join(', ');
|
|
114
|
-
}
|
|
115
|
-
async findCommand(options = {}) {
|
|
116
|
-
let query = `SELECT ${this.getSelectClause(options.aggregateFunction, options.fields)} FROM ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)}`;
|
|
117
|
-
query = this.addFiltersToQuery(query, options.filters);
|
|
118
|
-
if (!options.aggregateFunction) {
|
|
119
|
-
query = this.addOrderByToQuery(query, options.sorting);
|
|
120
|
-
query = this.addPaginationToQuery(query, options.pagination);
|
|
121
|
-
}
|
|
122
|
-
return (await this.runQuery(query)).rows;
|
|
123
|
-
}
|
|
124
|
-
sanitizeValue(value) {
|
|
125
|
-
if (Array.isArray(value)) {
|
|
126
|
-
const formattedArray = value
|
|
127
|
-
.map((item) => {
|
|
128
|
-
if (typeof item === 'string') {
|
|
129
|
-
return `'${item}'`;
|
|
130
|
-
}
|
|
131
|
-
else if (typeof item === 'object') {
|
|
132
|
-
return JSON.stringify(item);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
return item;
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
.join(',');
|
|
139
|
-
const isArrayWithObjects = value.some((item) => typeof item === 'object');
|
|
140
|
-
return isArrayWithObjects
|
|
141
|
-
? `ARRAY[${formattedArray}]::jsonb[]`
|
|
142
|
-
: `ARRAY[${formattedArray}]`;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
return pg_format_1.default.literal(value);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
async updateCommand(filters, data) {
|
|
149
|
-
let query = `UPDATE ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)} SET`;
|
|
150
|
-
const updateClauses = Object.entries(data).map(([key, value]) => {
|
|
151
|
-
const dbValue = this.sanitizeValue(value);
|
|
152
|
-
return `${pg_format_1.default.ident(key)} = ${dbValue}`;
|
|
153
|
-
});
|
|
154
|
-
query += ` ${updateClauses.join(', ')}`;
|
|
155
|
-
query += ' WHERE ';
|
|
156
|
-
query += this.buildFilterClause(Array.isArray(filters) ? filters : filters.filters, filters.logicOperator);
|
|
157
|
-
return this.runQuery(query);
|
|
158
|
-
}
|
|
159
|
-
async deleteCommand(filters) {
|
|
160
|
-
let query = `DELETE FROM ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)}`;
|
|
161
|
-
if (filters) {
|
|
162
|
-
query += ' WHERE ';
|
|
163
|
-
query += this.buildFilterClause(Array.isArray(filters) ? filters : filters.filters, filters.logicOperator);
|
|
164
|
-
}
|
|
165
|
-
return this.runQuery(query);
|
|
166
|
-
}
|
|
167
|
-
query(queryText, values) {
|
|
168
|
-
return this.runQuery(queryText, values);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
exports.default = PostgresqlClientService;
|
|
172
|
-
//# sourceMappingURL=postgreSqlClient.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postgreSqlClient.service.js","sourceRoot":"","sources":["../../../../../src/services/cruds/postgresql/postgreSqlClient.service.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,+BAA+B;;;;;AAE/B,0DAA+B;AAU/B,oEAA2C;AAC3C,wDAMkC;AAElC,8DAA4D;AAC5D,gEAAsE;AAEtE,MAAqB,uBAA2B,SAAQ,uBAAY;IAEhE,YAAY,WAA8B;QACtC,MAAM,iBAAiB,GAAG,WAAW,CAAC,OAAO,IAAI,KA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BAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,OAAO,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,KAAK,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAExC,KAAK,IAAI,SAAS,CAAC;QACnB,KAAK,IAAI,IAAI,CAAC,iBAAiB,CAC3B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAClD,OAAO,CAAC,aAAa,CACxB,CAAC;QAEF,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAyB;QACzC,IAAI,KAAK,GAAG,eAAe,mBAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,mBAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QACzF,IAAI,OAAO,EAAE,CAAC;YACV,KAAK,IAAI,SAAS,CAAC;YACnB,KAAK,IAAI,IAAI,CAAC,iBAAiB,CAC3B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAClD,OAAO,CAAC,aAAa,CACxB,CAAC;QACN,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,SAAiB,EAAE,MAAc;QACnC,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;CACJ;AAzND,0CAyNC"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PostgreSqlCrudService = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
-
const q_id_generator_1 = require("q-id-generator");
|
|
9
|
-
const postgreSqlClient_service_1 = __importDefault(require("./postgreSqlClient.service"));
|
|
10
|
-
const tableHelper_1 = require("../../../helpers/tableHelper");
|
|
11
|
-
const constants_1 = require("../../../utils/constants");
|
|
12
|
-
const queryHelpers_1 = require("../../../helpers/queryHelpers");
|
|
13
|
-
class PostgreSqlCrudService extends postgreSqlClient_service_1.default {
|
|
14
|
-
constructor(tableSchema) {
|
|
15
|
-
super(tableSchema);
|
|
16
|
-
this.tableSchema = tableSchema;
|
|
17
|
-
}
|
|
18
|
-
get idColumnName() {
|
|
19
|
-
return (0, tableHelper_1.findIdColumnName)(this.tableSchema.columns);
|
|
20
|
-
}
|
|
21
|
-
moveUndefinedColumnsToQvAttributes(inputData) {
|
|
22
|
-
inputData.qvAttributes = {};
|
|
23
|
-
for (const key in inputData) {
|
|
24
|
-
if (!this.tableSchema.columns[key] && key !== 'qvAttributes') {
|
|
25
|
-
inputData.qvAttributes[key] = inputData[key];
|
|
26
|
-
delete inputData[key];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
getItem(data) {
|
|
31
|
-
const resultItem = Object.assign(Object.assign({}, data), data.qvAttributes);
|
|
32
|
-
delete resultItem['qvAttributes'];
|
|
33
|
-
return resultItem;
|
|
34
|
-
}
|
|
35
|
-
create(entity) {
|
|
36
|
-
var _a;
|
|
37
|
-
let inputData = Object.assign({}, entity);
|
|
38
|
-
if (this.idColumnName) {
|
|
39
|
-
const idValue = ((_a = entity[this.idColumnName]) === null || _a === void 0 ? void 0 : _a.toString()) || (0, q_id_generator_1.getId)();
|
|
40
|
-
inputData = Object.assign(Object.assign({}, entity), { [this.idColumnName]: idValue });
|
|
41
|
-
}
|
|
42
|
-
this.moveUndefinedColumnsToQvAttributes(inputData);
|
|
43
|
-
return this.createCommand(inputData).then((data) => data.rows[0]);
|
|
44
|
-
}
|
|
45
|
-
findItem(findOptions) {
|
|
46
|
-
return this.findCommand(findOptions).then((data) => {
|
|
47
|
-
return (data === null || data === void 0 ? void 0 : data.length)
|
|
48
|
-
? this.getItem(data[0])
|
|
49
|
-
: null;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async processQueryResult(findOptions, omitPagination = false) {
|
|
53
|
-
const { pagination } = findOptions;
|
|
54
|
-
const rows = await this.findCommand(findOptions);
|
|
55
|
-
const items = rows.map((row) => this.getItem(row));
|
|
56
|
-
const result = {
|
|
57
|
-
items,
|
|
58
|
-
pagination: omitPagination ? null : pagination,
|
|
59
|
-
count: items.length,
|
|
60
|
-
};
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
async find(findOptions) {
|
|
64
|
-
return this.processQueryResult(findOptions);
|
|
65
|
-
}
|
|
66
|
-
async findAll(findOptions) {
|
|
67
|
-
return this.processQueryResult(findOptions, true);
|
|
68
|
-
}
|
|
69
|
-
async findCount(findOptions) {
|
|
70
|
-
const items = await this.findCommand(Object.assign(Object.assign({}, findOptions), { aggregateFunction: constants_1.AGGREGATE_FUNCTIONS.COUNT }));
|
|
71
|
-
const aggFunctionProperty = (0, queryHelpers_1.buildAggFunctionAlias)(constants_1.AGGREGATE_FUNCTIONS.COUNT);
|
|
72
|
-
const item = items.length ? items[0] : {};
|
|
73
|
-
return item[aggFunctionProperty] || 0;
|
|
74
|
-
}
|
|
75
|
-
async update(filters, data) {
|
|
76
|
-
const savedRecord = await this.findItem({ filters });
|
|
77
|
-
const inputData = Object.assign(Object.assign({}, savedRecord), data);
|
|
78
|
-
this.moveUndefinedColumnsToQvAttributes(inputData);
|
|
79
|
-
await this.updateCommand(filters, inputData);
|
|
80
|
-
return this.getItem(inputData);
|
|
81
|
-
}
|
|
82
|
-
async remove(filters) {
|
|
83
|
-
await this.deleteCommand(filters);
|
|
84
|
-
}
|
|
85
|
-
runQuery(querySentence, values) {
|
|
86
|
-
return super.runQuery(querySentence, values);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.PostgreSqlCrudService = PostgreSqlCrudService;
|
|
90
|
-
//# sourceMappingURL=postgreSqlCrud.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postgreSqlCrud.service.js","sourceRoot":"","sources":["../../../../../src/services/cruds/postgresql/postgreSqlCrud.service.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAuD;AACvD,mDAAuC;AACvC,0FAAiE;AASjE,8DAAgE;AAChE,wDAA+D;AAC/D,gEAAsE;AAEtE,MAAa,qBACT,SAAQ,kCAA0B;IAGlC,YAAoB,WAA8B;QAC9C,KAAK,CAAC,WAAW,CAAC,CAAC;QADH,gBAAW,GAAX,WAAW,CAAmB;IAElD,CAAC;IAED,IAAY,YAAY;QACpB,OAAO,IAAA,8BAAgB,EAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,kCAAkC,CAAC,SAAc;QAC7C,SAAS,CAAC,YAAY,GAAG,EAAE,CAAC;QAC5B,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,cAAc,EAAE,CAAC;gBAC3D,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;gBAC7C,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;YAC1B,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,CAAC,IAA4B;QAChC,MAAM,UAAU,mCAAQ,IAAI,GAAK,IAAI,CAAC,YAAY,CAAE,CAAC;QACrD,OAAO,UAAU,CAAC,cAAc,CAAC,CAAC;QAClC,OAAO,UAAU,CAAC;IACtB,CAAC;IAED,MAAM,CAAC,MAAS;;QACZ,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AC;IAED,QAAQ,CAAC,aAAqB,EAAE,MAAc;QAC1C,OAAO,KAAK,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;CACJ;AAjHD,sDAiHC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const connection_service_1 = __importDefault(require("./connection.service"));
|
|
7
|
-
class QueryService {
|
|
8
|
-
constructor(usePool) {
|
|
9
|
-
const connectionString = process.env.MULTIPLATFORM_PG_CONNECTION_STRING || '';
|
|
10
|
-
if (!connectionString) {
|
|
11
|
-
throw new Error('MULTIPLATFORM_PG_CONNECTION_STRING environment variable must be configured');
|
|
12
|
-
}
|
|
13
|
-
this.connectionService = new connection_service_1.default(usePool);
|
|
14
|
-
}
|
|
15
|
-
async runQuery(queryText, values) {
|
|
16
|
-
const client = await this.connectionService.getClient();
|
|
17
|
-
try {
|
|
18
|
-
const result = await client.query(queryText, values);
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
console.log('[Postgresql-Client] Query Execution Failed:', error);
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
finally {
|
|
26
|
-
this.connectionService.releaseClient(client);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.default = QueryService;
|
|
31
|
-
//# sourceMappingURL=query.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query.service.js","sourceRoot":"","sources":["../../../../../src/services/cruds/postgresql/query.service.ts"],"names":[],"mappings":";;;;;AAGA,8EAAqD;AAErD,MAAqB,YAAY;IAG7B,YAAY,OAAgB;QACxB,MAAM,gBAAgB,GAClB,OAAO,CAAC,GAAG,CAAC,kCAAkC,IAAI,EAAE,CAAC;QACzD,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CACX,4EAA4E,CAC/E,CAAC;QACN,CAAC;QAED,IAAI,CAAC,iBAAiB,GAAG,IAAI,4BAAiB,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,QAAQ,CACV,SAAiB,EACjB,MAAc;QAEd,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE,CAAC;QACxD,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YACrD,OAAO,MAAM,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;YAClE,MAAM,KAAK,CAAC;QAChB,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACjD,CAAC;IACL,CAAC;CACJ;AA9BD,+BA8BC"}
|