UNPKG

refql

Version:

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

32 lines (31 loc) 1.02 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/OrderBy"; const prototype = Object.assign({}, Operation_1.operationPrototype, { constructor: OrderBy, [consts_1.refqlType]: type, interpret }); function OrderBy(descending = false) { let orderBy = Object.create(prototype); orderBy.descending = descending; return orderBy; } function interpret(col) { const { descending } = this; const dir = descending ? "desc" : "asc"; return (0, sql_1.sqlX) ` ${col} ${(0, Raw_1.default)(dir)} `; } OrderBy.isOrderBy = function (x) { return x != null && x[consts_1.refqlType] === type; }; exports.default = OrderBy;