CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
conditions.cjs223 linesDownload Raw Back to expressions
1"use strict";2var __defProp = Object.defineProperty;3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;4var __getOwnPropNames = Object.getOwnPropertyNames;5var __hasOwnProp = Object.prototype.hasOwnProperty;6var __export = (target, all) => {7  for (var name in all)8    __defProp(target, name, { get: all[name], enumerable: true });9};10var __copyProps = (to, from, except, desc) => {11  if (from && typeof from === "object" || typeof from === "function") {12    for (let key of __getOwnPropNames(from))13      if (!__hasOwnProp.call(to, key) && key !== except)14        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });15  }16  return to;17};18var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);19var conditions_exports = {};20__export(conditions_exports, {21  and: () => and,22  arrayContained: () => arrayContained,23  arrayContains: () => arrayContains,24  arrayOverlaps: () => arrayOverlaps,25  between: () => between,26  bindIfParam: () => bindIfParam,27  eq: () => eq,28  exists: () => exists,29  gt: () => gt,30  gte: () => gte,31  ilike: () => ilike,32  inArray: () => inArray,33  isNotNull: () => isNotNull,34  isNull: () => isNull,35  like: () => like,36  lt: () => lt,37  lte: () => lte,38  ne: () => ne,39  not: () => not,40  notBetween: () => notBetween,41  notExists: () => notExists,42  notIlike: () => notIlike,43  notInArray: () => notInArray,44  notLike: () => notLike,45  or: () => or46});47module.exports = __toCommonJS(conditions_exports);48var import_column = require("../../column.cjs");49var import_entity = require("../../entity.cjs");50var import_table = require("../../table.cjs");51var import_sql = require("../sql.cjs");52function bindIfParam(value, column) {53  if ((0, import_sql.isDriverValueEncoder)(column) && !(0, import_sql.isSQLWrapper)(value) && !(0, import_entity.is)(value, import_sql.Param) && !(0, import_entity.is)(value, import_sql.Placeholder) && !(0, import_entity.is)(value, import_column.Column) && !(0, import_entity.is)(value, import_table.Table) && !(0, import_entity.is)(value, import_sql.View)) {54    return new import_sql.Param(value, column);55  }56  return value;57}58const eq = (left, right) => {59  return import_sql.sql`${left} = ${bindIfParam(right, left)}`;60};61const ne = (left, right) => {62  return import_sql.sql`${left} <> ${bindIfParam(right, left)}`;63};64function and(...unfilteredConditions) {65  const conditions = unfilteredConditions.filter(66    (c) => c !== void 067  );68  if (conditions.length === 0) {69    return void 0;70  }71  if (conditions.length === 1) {72    return new import_sql.SQL(conditions);73  }74  return new import_sql.SQL([75    new import_sql.StringChunk("("),76    import_sql.sql.join(conditions, new import_sql.StringChunk(" and ")),77    new import_sql.StringChunk(")")78  ]);79}80function or(...unfilteredConditions) {81  const conditions = unfilteredConditions.filter(82    (c) => c !== void 083  );84  if (conditions.length === 0) {85    return void 0;86  }87  if (conditions.length === 1) {88    return new import_sql.SQL(conditions);89  }90  return new import_sql.SQL([91    new import_sql.StringChunk("("),92    import_sql.sql.join(conditions, new import_sql.StringChunk(" or ")),93    new import_sql.StringChunk(")")94  ]);95}96function not(condition) {97  return import_sql.sql`not ${condition}`;98}99const gt = (left, right) => {100  return import_sql.sql`${left} > ${bindIfParam(right, left)}`;101};102const gte = (left, right) => {103  return import_sql.sql`${left} >= ${bindIfParam(right, left)}`;104};105const lt = (left, right) => {106  return import_sql.sql`${left} < ${bindIfParam(right, left)}`;107};108const lte = (left, right) => {109  return import_sql.sql`${left} <= ${bindIfParam(right, left)}`;110};111function inArray(column, values) {112  if (Array.isArray(values)) {113    if (values.length === 0) {114      return import_sql.sql`false`;115    }116    return import_sql.sql`${column} in ${values.map((v) => bindIfParam(v, column))}`;117  }118  return import_sql.sql`${column} in ${bindIfParam(values, column)}`;119}120function notInArray(column, values) {121  if (Array.isArray(values)) {122    if (values.length === 0) {123      return import_sql.sql`true`;124    }125    return import_sql.sql`${column} not in ${values.map((v) => bindIfParam(v, column))}`;126  }127  return import_sql.sql`${column} not in ${bindIfParam(values, column)}`;128}129function isNull(value) {130  return import_sql.sql`${value} is null`;131}132function isNotNull(value) {133  return import_sql.sql`${value} is not null`;134}135function exists(subquery) {136  return import_sql.sql`exists ${subquery}`;137}138function notExists(subquery) {139  return import_sql.sql`not exists ${subquery}`;140}141function between(column, min, max) {142  return import_sql.sql`${column} between ${bindIfParam(min, column)} and ${bindIfParam(143    max,144    column145  )}`;146}147function notBetween(column, min, max) {148  return import_sql.sql`${column} not between ${bindIfParam(149    min,150    column151  )} and ${bindIfParam(max, column)}`;152}153function like(column, value) {154  return import_sql.sql`${column} like ${value}`;155}156function notLike(column, value) {157  return import_sql.sql`${column} not like ${value}`;158}159function ilike(column, value) {160  return import_sql.sql`${column} ilike ${value}`;161}162function notIlike(column, value) {163  return import_sql.sql`${column} not ilike ${value}`;164}165function arrayContains(column, values) {166  if (Array.isArray(values)) {167    if (values.length === 0) {168      throw new Error("arrayContains requires at least one value");169    }170    const array = import_sql.sql`${bindIfParam(values, column)}`;171    return import_sql.sql`${column} @> ${array}`;172  }173  return import_sql.sql`${column} @> ${bindIfParam(values, column)}`;174}175function arrayContained(column, values) {176  if (Array.isArray(values)) {177    if (values.length === 0) {178      throw new Error("arrayContained requires at least one value");179    }180    const array = import_sql.sql`${bindIfParam(values, column)}`;181    return import_sql.sql`${column} <@ ${array}`;182  }183  return import_sql.sql`${column} <@ ${bindIfParam(values, column)}`;184}185function arrayOverlaps(column, values) {186  if (Array.isArray(values)) {187    if (values.length === 0) {188      throw new Error("arrayOverlaps requires at least one value");189    }190    const array = import_sql.sql`${bindIfParam(values, column)}`;191    return import_sql.sql`${column} && ${array}`;192  }193  return import_sql.sql`${column} && ${bindIfParam(values, column)}`;194}195// Annotate the CommonJS export names for ESM import in node:1960 && (module.exports = {197  and,198  arrayContained,199  arrayContains,200  arrayOverlaps,201  between,202  bindIfParam,203  eq,204  exists,205  gt,206  gte,207  ilike,208  inArray,209  isNotNull,210  isNull,211  like,212  lt,213  lte,214  ne,215  not,216  notBetween,217  notExists,218  notIlike,219  notInArray,220  notLike,221  or222});223//# sourceMappingURL=conditions.cjs.map