UNPKG

refql

Version:

A Node.js and Deno library for composing and running SQL queries.

35 lines (34 loc) 1.26 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const consts_1 = require("../common/consts"); const Raw_1 = __importDefault(require("../SQLTag/Raw")); const sql_1 = require("../SQLTag/sql"); const Operation_1 = require("./Operation"); const type = "refql/Like"; const prototype = Object.assign({}, Operation_1.operationPrototype, { constructor: Like, [consts_1.refqlType]: type, interpret }); function Like(run, caseSensitive = false, notLike = false) { let like = Object.create(prototype); like.run = (typeof run === "function" ? run : () => run); like.caseSensitive = caseSensitive; like.notLike = notLike; return like; } function interpret(col, displayAnd) { const { run, caseSensitive, notLike } = this; const like = caseSensitive ? "like" : "ilike"; const equality = notLike ? `not ${like}` : like; return (0, sql_1.sqlX) ` ${(0, Raw_1.default)(displayAnd ? "and " : "")}${col} ${(0, Raw_1.default)(equality)} ${run} `; } Like.isLike = function (x) { return x != null && x[consts_1.refqlType] === type; }; exports.default = Like;