UNPKG

dogmaql.driver.redis

Version:

Redis driver for DogmaQL (Dogma Query Language).

61 lines (59 loc) 2.06 kB
"use strict"; var _dogmalang = require("dogmalang"); const time = _dogmalang.dogma.use(require("./time")); const $SearchTrans = class SearchTrans { constructor() { {} } }; const SearchTrans = new Proxy($SearchTrans, { apply(receiver, self, args) { return new $SearchTrans(...args); } });module.exports = exports = SearchTrans; SearchTrans.prototype.transSearchItem = function (stmt) { _dogmalang.dogma.paramExpected("stmt", stmt, null);{ return transSearchItem(stmt); } }; function transSearchItem(stmt) { _dogmalang.dogma.paramExpected("stmt", stmt, null);{ return [["ft.search", stmt.table, transNode(stmt.where.root)]]; } } function transNode(node) { _dogmalang.dogma.paramExpected("node", node, null);{ return transBinOp(node); } } function transBinOp(node) { let code = "";_dogmalang.dogma.paramExpected("node", node, null);{ const $aux15187793585803 = node.op;if ($aux15187793585803 == "like") { code = transLikeOp(node); } else if ($aux15187793585803 == "notlike") { code = transNotLikeOp(node); } else if ($aux15187793585803 == "and") { code = transAndOp(node); } else { code = transOrOp(node); } }return code; } function transLikeOp(node) { _dogmalang.dogma.paramExpected("node", node, null);{ return node.left.value == "any" ? (0, _dogmalang.fmt)("\"%s\"", node.right.value) : (0, _dogmalang.fmt)("@%s:\"%s\"", node.left.value, node.right.value); } } function transNotLikeOp(node) { _dogmalang.dogma.paramExpected("node", node, null);{ return node.left.value == "any" ? (0, _dogmalang.fmt)("-\"%s\"", node.right.value) : (0, _dogmalang.fmt)("-@%s:\"%s\"", node.left.value, node.right.value); } } function transAndOp(node) { _dogmalang.dogma.paramExpected("node", node, null);{ return (0, _dogmalang.fmt)("%s %s", transNode(node.left), transNode(node.right)); } } function transOrOp(node) { _dogmalang.dogma.paramExpected("node", node, null);{ return (0, _dogmalang.fmt)("(%s|%s)", transNode(node.left), transNode(node.right)); } }