CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
integer.cjs158 linesDownload Raw Back to columns
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 integer_exports = {};20__export(integer_exports, {21  SQLiteBaseInteger: () => SQLiteBaseInteger,22  SQLiteBaseIntegerBuilder: () => SQLiteBaseIntegerBuilder,23  SQLiteBoolean: () => SQLiteBoolean,24  SQLiteBooleanBuilder: () => SQLiteBooleanBuilder,25  SQLiteInteger: () => SQLiteInteger,26  SQLiteIntegerBuilder: () => SQLiteIntegerBuilder,27  SQLiteTimestamp: () => SQLiteTimestamp,28  SQLiteTimestampBuilder: () => SQLiteTimestampBuilder,29  int: () => int,30  integer: () => integer31});32module.exports = __toCommonJS(integer_exports);33var import_entity = require("../../entity.cjs");34var import_sql = require("../../sql/sql.cjs");35var import_utils = require("../../utils.cjs");36var import_common = require("./common.cjs");37class SQLiteBaseIntegerBuilder extends import_common.SQLiteColumnBuilder {38  static [import_entity.entityKind] = "SQLiteBaseIntegerBuilder";39  constructor(name, dataType, columnType) {40    super(name, dataType, columnType);41    this.config.autoIncrement = false;42  }43  primaryKey(config) {44    if (config?.autoIncrement) {45      this.config.autoIncrement = true;46    }47    this.config.hasDefault = true;48    return super.primaryKey();49  }50}51class SQLiteBaseInteger extends import_common.SQLiteColumn {52  static [import_entity.entityKind] = "SQLiteBaseInteger";53  autoIncrement = this.config.autoIncrement;54  getSQLType() {55    return "integer";56  }57}58class SQLiteIntegerBuilder extends SQLiteBaseIntegerBuilder {59  static [import_entity.entityKind] = "SQLiteIntegerBuilder";60  constructor(name) {61    super(name, "number", "SQLiteInteger");62  }63  build(table) {64    return new SQLiteInteger(65      table,66      this.config67    );68  }69}70class SQLiteInteger extends SQLiteBaseInteger {71  static [import_entity.entityKind] = "SQLiteInteger";72}73class SQLiteTimestampBuilder extends SQLiteBaseIntegerBuilder {74  static [import_entity.entityKind] = "SQLiteTimestampBuilder";75  constructor(name, mode) {76    super(name, "date", "SQLiteTimestamp");77    this.config.mode = mode;78  }79  /**80   * @deprecated Use `default()` with your own expression instead.81   *82   * Adds `DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer))` to the column, which is the current epoch timestamp in milliseconds.83   */84  defaultNow() {85    return this.default(import_sql.sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`);86  }87  build(table) {88    return new SQLiteTimestamp(89      table,90      this.config91    );92  }93}94class SQLiteTimestamp extends SQLiteBaseInteger {95  static [import_entity.entityKind] = "SQLiteTimestamp";96  mode = this.config.mode;97  mapFromDriverValue(value) {98    if (this.config.mode === "timestamp") {99      return new Date(value * 1e3);100    }101    return new Date(value);102  }103  mapToDriverValue(value) {104    const unix = value.getTime();105    if (this.config.mode === "timestamp") {106      return Math.floor(unix / 1e3);107    }108    return unix;109  }110}111class SQLiteBooleanBuilder extends SQLiteBaseIntegerBuilder {112  static [import_entity.entityKind] = "SQLiteBooleanBuilder";113  constructor(name, mode) {114    super(name, "boolean", "SQLiteBoolean");115    this.config.mode = mode;116  }117  build(table) {118    return new SQLiteBoolean(119      table,120      this.config121    );122  }123}124class SQLiteBoolean extends SQLiteBaseInteger {125  static [import_entity.entityKind] = "SQLiteBoolean";126  mode = this.config.mode;127  mapFromDriverValue(value) {128    return Number(value) === 1;129  }130  mapToDriverValue(value) {131    return value ? 1 : 0;132  }133}134function integer(a, b) {135  const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);136  if (config?.mode === "timestamp" || config?.mode === "timestamp_ms") {137    return new SQLiteTimestampBuilder(name, config.mode);138  }139  if (config?.mode === "boolean") {140    return new SQLiteBooleanBuilder(name, config.mode);141  }142  return new SQLiteIntegerBuilder(name);143}144const int = integer;145// Annotate the CommonJS export names for ESM import in node:1460 && (module.exports = {147  SQLiteBaseInteger,148  SQLiteBaseIntegerBuilder,149  SQLiteBoolean,150  SQLiteBooleanBuilder,151  SQLiteInteger,152  SQLiteIntegerBuilder,153  SQLiteTimestamp,154  SQLiteTimestampBuilder,155  int,156  integer157});158//# sourceMappingURL=integer.cjs.map