refql
Version:
A Node.js and Deno library for composing and running SQL queries.
34 lines (33 loc) • 1.2 kB
JavaScript
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 Values_1 = __importDefault(require("../SQLTag/Values"));
const Operation_1 = require("./Operation");
const type = "refql/In";
const prototype = Object.assign({}, Operation_1.operationPrototype, {
constructor: In,
[consts_1.refqlType]: type,
interpret
});
function In(run, notIn = false) {
let whereIn = Object.create(prototype);
whereIn.run = (typeof run === "function" ? run : () => run);
whereIn.notIn = notIn;
return whereIn;
}
function interpret(col, displayAnd) {
const { notIn, run } = this;
const equality = notIn ? "not in" : "in";
return (0, sql_1.sqlX) `
${(0, Raw_1.default)(displayAnd ? "and " : "")}${col} ${(0, Raw_1.default)(equality)} ${(0, Values_1.default)(run)}
`;
}
In.isIn = function (x) {
return x != null && x[consts_1.refqlType] === type;
};
exports.default = In;
;