@qrvey/data-persistence
Advanced tools
Comparing version 0.2.7 to 0.2.8
@@ -41,2 +41,3 @@ "use strict"; | ||
buildClause(operator, attribute, value) { | ||
var _a; | ||
const formattedValue = pg_format_1.default.literal(value); | ||
@@ -51,2 +52,3 @@ operator = operator | ||
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 | ||
@@ -74,2 +76,17 @@ ? filterProperty | ||
} | ||
if ((operator === constants_1.FilterOperator.CONTAINS || | ||
operator === constants_1.FilterOperator.NOT_CONTAINS) && | ||
columnType === 'array') { | ||
const filterValue = typeof value === 'number' ? value : `'${value}'`; | ||
let filterString = `${filterValue} = ANY(${property})`; | ||
if (operator === constants_1.FilterOperator.NOT_CONTAINS) { | ||
if (value === null) { | ||
filterString = `(NOT (${filterString}))`; | ||
} | ||
else { | ||
filterString = `(NOT (${filterString}) or ${property} IS NULL)`; | ||
} | ||
} | ||
return filterString; | ||
} | ||
const wildcardValue = this.getWildcardValue(operator, value); | ||
@@ -129,5 +146,28 @@ return `${property} ${postgresOperator} ${pg_format_1.default.literal(wildcardValue)}`; | ||
} | ||
formatArray(array) { | ||
const isNumberArray = typeof array[0] === 'number'; | ||
if (isNumberArray) { | ||
return `{${array.join(',')}}`; | ||
} | ||
else { | ||
return `{${array.map((val) => `"${val}"`).join(',')}}`; | ||
} | ||
} | ||
formatValue(value) { | ||
if (Array.isArray(value)) { | ||
if (!(value === null || value === void 0 ? void 0 : value.length)) | ||
return '{}'; | ||
const isNumberArray = typeof value[0] === 'number'; | ||
if (isNumberArray) { | ||
return `{${value.join(',')}}`; | ||
} | ||
else { | ||
return `{${value.map((val) => `"${val}"`).join(',')}}`; | ||
} | ||
} | ||
return value; | ||
} | ||
async createCommand(data) { | ||
const keys = Object.keys(data[0]); // Assuming all objects have the same keys | ||
const values = data.map((item) => Object.values(item)); | ||
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); | ||
@@ -134,0 +174,0 @@ return this.runQuery(query); |
@@ -22,2 +22,3 @@ "use strict"; | ||
normalizeInputData(inputData) { | ||
var _a; | ||
inputData.qvAttributes = {}; | ||
@@ -29,3 +30,4 @@ for (const key in inputData) { | ||
} | ||
else if (Array.isArray(inputData[key])) { | ||
else if (Array.isArray(inputData[key]) && | ||
((_a = this.tableSchema.columns[key]) === null || _a === void 0 ? void 0 : _a.type) !== 'array') { | ||
inputData[key] = JSON.stringify(inputData[key]); | ||
@@ -32,0 +34,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"main": "dist/cjs/index.js", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
331559
3663