CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
text.js69 linesDownload Raw Back to columns
1import { entityKind } from "../../entity.js";2import { getColumnNameAndConfig } from "../../utils.js";3import { SQLiteColumn, SQLiteColumnBuilder } from "./common.js";4class SQLiteTextBuilder extends SQLiteColumnBuilder {5  static [entityKind] = "SQLiteTextBuilder";6  constructor(name, config) {7    super(name, "string", "SQLiteText");8    this.config.enumValues = config.enum;9    this.config.length = config.length;10  }11  /** @internal */12  build(table) {13    return new SQLiteText(14      table,15      this.config16    );17  }18}19class SQLiteText extends SQLiteColumn {20  static [entityKind] = "SQLiteText";21  enumValues = this.config.enumValues;22  length = this.config.length;23  constructor(table, config) {24    super(table, config);25  }26  getSQLType() {27    return `text${this.config.length ? `(${this.config.length})` : ""}`;28  }29}30class SQLiteTextJsonBuilder extends SQLiteColumnBuilder {31  static [entityKind] = "SQLiteTextJsonBuilder";32  constructor(name) {33    super(name, "json", "SQLiteTextJson");34  }35  /** @internal */36  build(table) {37    return new SQLiteTextJson(38      table,39      this.config40    );41  }42}43class SQLiteTextJson extends SQLiteColumn {44  static [entityKind] = "SQLiteTextJson";45  getSQLType() {46    return "text";47  }48  mapFromDriverValue(value) {49    return JSON.parse(value);50  }51  mapToDriverValue(value) {52    return JSON.stringify(value);53  }54}55function text(a, b = {}) {56  const { name, config } = getColumnNameAndConfig(a, b);57  if (config.mode === "json") {58    return new SQLiteTextJsonBuilder(name);59  }60  return new SQLiteTextBuilder(name, config);61}62export {63  SQLiteText,64  SQLiteTextBuilder,65  SQLiteTextJson,66  SQLiteTextJsonBuilder,67  text68};69//# sourceMappingURL=text.js.map