@qrvey/data-persistence
Advanced tools
Comparing version
@@ -8,3 +8,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const pg_format_1 = __importDefault(require("pg-format")); | ||
const pg_format_1 = require("@scaleleap/pg-format"); | ||
const query_service_1 = __importDefault(require("./query.service")); | ||
@@ -43,3 +43,3 @@ const constants_1 = require("../../../utils/constants"); | ||
var _a; | ||
const formattedValue = pg_format_1.default.literal(value); | ||
const formattedValue = (0, pg_format_1.literal)(value); | ||
operator = operator | ||
@@ -51,3 +51,3 @@ ? operator.toUpperCase() | ||
throw new Error(`Unsupported filter operator: ${operator}`); | ||
const filterProperty = pg_format_1.default.ident(attribute); | ||
const filterProperty = (0, pg_format_1.ident)(attribute); | ||
const columnExists = !!this.crudSchema.columns[attribute]; | ||
@@ -60,3 +60,3 @@ const columnType = columnExists && ((_a = this.crudSchema.columns[attribute]) === null || _a === void 0 ? void 0 : _a.type); | ||
const formattedValues = Array.isArray(value) | ||
? value.map(pg_format_1.default.literal) | ||
? value.map(pg_format_1.literal) | ||
: [formattedValue]; | ||
@@ -72,3 +72,3 @@ return `${property} ${postgresOperator} (${formattedValues.join(', ')})`; | ||
if (operator === constants_1.FilterOperator.NOT_EQUAL && value !== null) { | ||
return `(${property} ${postgresOperator} ${pg_format_1.default.literal(value)} OR ${property} IS NULL)`; | ||
return `(${property} ${postgresOperator} ${(0, pg_format_1.literal)(value)} OR ${property} IS NULL)`; | ||
} | ||
@@ -95,3 +95,3 @@ if (operator === constants_1.FilterOperator.NOT_EXIST || | ||
const wildcardValue = this.getWildcardValue(operator, value); | ||
return `${property} ${postgresOperator} ${pg_format_1.default.literal(wildcardValue)}`; | ||
return `${property} ${postgresOperator} ${(0, pg_format_1.literal)(wildcardValue)}`; | ||
} | ||
@@ -139,3 +139,3 @@ buildFilterClause(filters, logicOperator) { | ||
formatOrderByItem(sort) { | ||
return `${pg_format_1.default.ident(sort.column)} ${sort.direction || constants_1.SORT_DIRECTIONS.ASC}`; | ||
return `${(0, pg_format_1.ident)(sort.column)} ${sort.direction || constants_1.SORT_DIRECTIONS.ASC}`; | ||
} | ||
@@ -176,3 +176,3 @@ buildOrderByClause(querySorting) { | ||
const values = data.map((item) => keys.map((key) => this.formatValue(item[key]))); | ||
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); | ||
const query = (0, pg_format_1.format)(`INSERT INTO ${(0, pg_format_1.ident)(this.dbSchema)}.${(0, pg_format_1.ident)(this.tableName)} (%I) VALUES %L RETURNING *;`, keys, values); | ||
return this.runQuery(query); | ||
@@ -224,3 +224,3 @@ } | ||
async findCommand(options = {}) { | ||
let query = `SELECT ${this.getSelectClause(options.aggregateFunction, options.fields)} FROM ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)}`; | ||
let query = `SELECT ${this.getSelectClause(options.aggregateFunction, options.fields)} FROM ${(0, pg_format_1.ident)(this.dbSchema)}.${(0, pg_format_1.ident)(this.tableName)}`; | ||
query = this.addFiltersToQuery(query, options.filters); | ||
@@ -253,10 +253,10 @@ if (!options.aggregateFunction) { | ||
else { | ||
return pg_format_1.default.literal(value); | ||
return (0, pg_format_1.literal)(value); | ||
} | ||
} | ||
async updateCommand(filters, data) { | ||
let query = `UPDATE ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)} SET`; | ||
let query = `UPDATE ${(0, pg_format_1.ident)(this.dbSchema)}.${(0, pg_format_1.ident)(this.tableName)} SET`; | ||
const updateClauses = Object.entries(data).map(([key, value]) => { | ||
const dbValue = pg_format_1.default.literal(this.formatValue(value)); | ||
return `${pg_format_1.default.ident(key)} = ${dbValue}`; | ||
const dbValue = (0, pg_format_1.literal)(this.formatValue(value)); | ||
return `${(0, pg_format_1.ident)(key)} = ${dbValue}`; | ||
}); | ||
@@ -275,3 +275,3 @@ query += ` ${updateClauses.join(', ')}`; | ||
async deleteCommand(filters, useFilterGroups = false) { | ||
let query = `DELETE FROM ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)}`; | ||
let query = `DELETE FROM ${(0, pg_format_1.ident)(this.dbSchema)}.${(0, pg_format_1.ident)(this.tableName)}`; | ||
if (filters) { | ||
@@ -294,3 +294,3 @@ query += ' WHERE '; | ||
filters, actions, options = {}) { | ||
let query = `UPDATE ${pg_format_1.default.ident(this.dbSchema)}.${pg_format_1.default.ident(this.tableName)} SET`; | ||
let query = `UPDATE ${(0, pg_format_1.ident)(this.dbSchema)}.${(0, pg_format_1.ident)(this.tableName)} SET`; | ||
const set = actions.SET || []; | ||
@@ -338,7 +338,7 @@ const add = actions.ADD || []; | ||
case 'array': | ||
formattedValue = pg_format_1.default.literal(value); | ||
formattedValue = (0, pg_format_1.literal)(value); | ||
expValue = `ARRAY[${formattedValue}]`; | ||
break; | ||
default: | ||
formattedValue = pg_format_1.default.literal(value); | ||
formattedValue = (0, pg_format_1.literal)(value); | ||
expValue = formattedValue; | ||
@@ -348,3 +348,3 @@ break; | ||
this.crudSchema.columns; | ||
updateClauses.push(`${pg_format_1.default.ident(path)} = ${expValue}`); | ||
updateClauses.push(`${(0, pg_format_1.ident)(path)} = ${expValue}`); | ||
} | ||
@@ -361,3 +361,3 @@ }); | ||
queryFunctions.forEach((queryFunction) => { | ||
updateClauses.push(`${pg_format_1.default.ident(queryFunction.path)} = ${queryFunction.value}`); | ||
updateClauses.push(`${(0, pg_format_1.ident)(queryFunction.path)} = ${queryFunction.value}`); | ||
}); | ||
@@ -364,0 +364,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"main": "dist/cjs/index.js", | ||
"version": "0.3.6-bundle", | ||
"version": "0.3.6-bundle-1", | ||
"license": "MIT", | ||
@@ -36,4 +36,4 @@ "exports": { | ||
"@aws-sdk/lib-dynamodb": "3.x", | ||
"pg": "8.11.4", | ||
"pg-format": "1.0.4" | ||
"@scaleleap/pg-format": "^1.0.0", | ||
"pg": "8.11.4" | ||
}, | ||
@@ -40,0 +40,0 @@ "devDependencies": { |
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
355617
-0.19%3958
-0.05%+ Added
+ Added
- Removed
- Removed