@qrvey/data-persistence
Advanced tools
Comparing version 0.0.6-6 to 0.0.6-7
@@ -38,6 +38,2 @@ "use strict"; | ||
} | ||
isKeyword(attribute) { | ||
var _a; | ||
return (_a = this.crudSchema.columns[attribute]) === null || _a === void 0 ? void 0 : _a.keyword; | ||
} | ||
buildClause(operator, attribute, value) { | ||
@@ -51,5 +47,3 @@ const formattedValue = pg_format_1.default.literal(value); | ||
throw new Error(`Unsupported filter operator: ${operator}`); | ||
const filterProperty = this.isKeyword(attribute) | ||
? `'${attribute}'` | ||
: pg_format_1.default.ident(attribute); | ||
const filterProperty = pg_format_1.default.ident(attribute); | ||
if (operator === constants_1.FilterOperator.IN) { | ||
@@ -70,2 +64,10 @@ const formattedValues = Array.isArray(value) | ||
} | ||
if (operator === constants_1.FilterOperator.NOT_EXIST || | ||
operator === constants_1.FilterOperator.EXIST) { | ||
const columnExists = !!this.crudSchema.columns[attribute]; | ||
const property = columnExists | ||
? filterProperty | ||
: `("qvAttributes" ->> '${attribute}')`; | ||
return `${property} ${postgresOperator}`; | ||
} | ||
const wildcardValue = this.getWildcardValue(operator, value); | ||
@@ -72,0 +74,0 @@ return `${filterProperty} ${postgresOperator} ${pg_format_1.default.literal(wildcardValue)}`; |
@@ -54,2 +54,4 @@ "use strict"; | ||
FilterOperator["BETWEEN"] = "BETWEEN"; | ||
FilterOperator["EXIST"] = "EXIST"; | ||
FilterOperator["NOT_EXIST"] = "NOT_EXIST"; | ||
})(FilterOperator || (exports.FilterOperator = FilterOperator = {})); | ||
@@ -72,2 +74,4 @@ exports.POSTGRES_FILTER_OPERATOR_MAP = { | ||
BETWEEN: 'BETWEEN', | ||
EXIST: 'IS NOT NULL', | ||
NOT_EXIST: 'IS NULL', | ||
}; | ||
@@ -74,0 +78,0 @@ exports.DEFAULT_PG_SCHEMA = 'public'; |
@@ -93,3 +93,2 @@ interface IFilter { | ||
default?: any; | ||
keyword?: boolean; | ||
}; | ||
@@ -118,3 +117,3 @@ } | ||
findCount(options: IFindOptions): Promise<number>; | ||
buildFilter(attribute: string, value: string, operator?: string): { | ||
buildFilter(attribute: string, value: any, operator?: string): { | ||
attribute: string; | ||
@@ -121,0 +120,0 @@ operator: string; |
@@ -5,3 +5,3 @@ { | ||
"main": "dist/cjs/index.js", | ||
"version": "0.0.6-6", | ||
"version": "0.0.6-7", | ||
"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
123465
1650