Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@qrvey/data-persistence

Package Overview
Dependencies
Maintainers
11
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qrvey/data-persistence - npm Package Compare versions

Comparing version 0.2.7 to 0.2.8

dist/esm/postgreSqlCrud.service-Q2QGZ3FN.mjs

42

dist/cjs/services/cruds/postgresql/postgreSqlClient.service.js

@@ -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);

4

dist/cjs/services/cruds/postgresql/postgreSqlCrud.service.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc