redis-orm-node
Version:
`redis-orm` is a lightweight Object-Relational Mapping (ORM) library for Node.js.
33 lines • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseParameters = exports.convertWhere = void 0;
const utils_1 = require("../utils");
const operators_1 = require("./operators");
const FindOperators_1 = require("../operators/FindOperators");
const wheresToRedisQuery_1 = require("./wheresToRedisQuery");
function convertWhere(schema, ...wheres) {
if (!wheres.length)
return "";
return (0, wheresToRedisQuery_1.wheresToRedisQuery)(wheres.map(where => parseParameters(where, schema)).flat(), schema.properties);
}
exports.convertWhere = convertWhere;
function parseParameters(where, schema) {
const filters = [];
for (let key in where) {
if (!(key in schema.properties))
throw new Error(`${key} not exist in ${schema.name} entity.`);
const value = where[key];
const schemaPropertyType = schema.properties[key];
if ((0, utils_1.isFindOperator)(value))
filters.push((0, operators_1.OperatorMapper)(value, key, schemaPropertyType.type));
else if ((0, utils_1.isPrimitive)(value))
filters.push((0, operators_1.OperatorMapper)((0, FindOperators_1.Equal)(value), key, schemaPropertyType.type));
else if (value === undefined)
continue;
else
throw new Error("Value type not supported.");
}
return filters;
}
exports.parseParameters = parseParameters;
//# sourceMappingURL=where.js.map