@qrvey/data-persistence
Advanced tools
Comparing version 0.3.6-bundle-1 to 0.3.6-bundle-2
@@ -40,3 +40,3 @@ "use strict"; | ||
} | ||
buildClause(operator, attribute, value) { | ||
buildClause(operator, attribute, relativePath, value) { | ||
var _a; | ||
@@ -50,8 +50,19 @@ const formattedValue = (0, pg_format_1.literal)(value); | ||
throw new Error(`Unsupported filter operator: ${operator}`); | ||
let property; | ||
const filterProperty = (0, pg_format_1.ident)(attribute); | ||
const columnExists = !!this.crudSchema.columns[attribute]; | ||
const columnType = columnExists && ((_a = this.crudSchema.columns[attribute]) === null || _a === void 0 ? void 0 : _a.type); | ||
const property = columnExists | ||
? filterProperty | ||
: `("qvAttributes" ->> '${attribute}')`; | ||
if (relativePath != undefined) { | ||
const attributePath = relativePath.split('.').join(','); | ||
property = `("${attribute}" #> '{${attributePath}}')`; | ||
if (value != null) { | ||
const comparisonValueType = this.getValueTypeAsPostgresDefinition(value); | ||
property += `::${comparisonValueType}`; | ||
} | ||
} | ||
else { | ||
property = columnExists | ||
? filterProperty | ||
: `("qvAttributes" ->> '${attribute}')`; | ||
} | ||
if (operator === constants_1.FilterOperator.IN) { | ||
@@ -97,3 +108,3 @@ const formattedValues = Array.isArray(value) | ||
const filterClauses = filters.map((filter) => { | ||
return this.buildClause(filter.operator, filter.attribute, filter.value); | ||
return this.buildClause(filter.operator, filter.attribute, filter.relativePath, filter.value); | ||
}); | ||
@@ -125,3 +136,3 @@ return filterClauses.join(` ${logicOperator !== null && logicOperator !== void 0 ? logicOperator : constants_1.FILTER_LOGIC_OPERATORS.AND} `); | ||
else { | ||
clause = this.buildClause(filter.operator, filter.attribute, filter.value); | ||
clause = this.buildClause(filter.operator, filter.attribute, filter.relativePath, filter.value); | ||
} | ||
@@ -357,2 +368,3 @@ filterClauses += `${clause} ${key} `; | ||
query += this.buildFilterClause(filters); | ||
console.log('query: ', query); | ||
return this.runQuery(query); | ||
@@ -544,4 +556,15 @@ } | ||
} | ||
getValueTypeAsPostgresDefinition(value) { | ||
switch (typeof value) { | ||
case 'number': | ||
return 'number'; | ||
case 'boolean': | ||
return 'boolean'; | ||
case 'string': | ||
default: | ||
return 'text'; | ||
} | ||
} | ||
} | ||
exports.default = PostgresqlClientService; | ||
//# sourceMappingURL=postgreSqlClient.service.js.map |
@@ -48,7 +48,11 @@ "use strict"; | ||
const inputDataArray = data.map((item) => this.prepareData(item)); | ||
return this.createCommand(inputDataArray).then((result) => ({ | ||
unprocessedItems: result | ||
.filter((r) => !r.success) | ||
.map((r) => r.inputData), | ||
})); | ||
return this.createCommand(inputDataArray).then((result) => { | ||
var _a, _b; | ||
const items = ((_a = result === null || result === void 0 ? void 0 : result.rows) === null || _a === void 0 ? void 0 : _a.map((row) => this.getItem(row))) || []; | ||
return { | ||
total: (_b = result.rowCount) !== null && _b !== void 0 ? _b : 0, | ||
items, | ||
unprocessedItems: [], | ||
}; | ||
}); | ||
} | ||
@@ -55,0 +59,0 @@ else { |
@@ -6,2 +6,3 @@ import * as pg from 'pg'; | ||
attribute: string; | ||
relativePath?: string; | ||
operator?: string; | ||
@@ -17,3 +18,5 @@ value: unknown; | ||
interface ICreateMultipleResponse { | ||
unprocessedItems: Record<string, any>; | ||
unprocessedItems?: Record<string, any>; | ||
total?: number; | ||
items?: any[]; | ||
} | ||
@@ -20,0 +23,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"main": "dist/cjs/index.js", | ||
"version": "0.3.6-bundle-1", | ||
"version": "0.3.6-bundle-2", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "exports": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
360068
4018