text.cjs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __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. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var text_exports = {};
  20. __export(text_exports, {
  21. SQLiteText: () => SQLiteText,
  22. SQLiteTextBuilder: () => SQLiteTextBuilder,
  23. SQLiteTextJson: () => SQLiteTextJson,
  24. SQLiteTextJsonBuilder: () => SQLiteTextJsonBuilder,
  25. text: () => text
  26. });
  27. module.exports = __toCommonJS(text_exports);
  28. var import_entity = require("../../entity.cjs");
  29. var import_utils = require("../../utils.cjs");
  30. var import_common = require("./common.cjs");
  31. class SQLiteTextBuilder extends import_common.SQLiteColumnBuilder {
  32. static [import_entity.entityKind] = "SQLiteTextBuilder";
  33. constructor(name, config) {
  34. super(name, "string", "SQLiteText");
  35. this.config.enumValues = config.enum;
  36. this.config.length = config.length;
  37. }
  38. /** @internal */
  39. build(table) {
  40. return new SQLiteText(
  41. table,
  42. this.config
  43. );
  44. }
  45. }
  46. class SQLiteText extends import_common.SQLiteColumn {
  47. static [import_entity.entityKind] = "SQLiteText";
  48. enumValues = this.config.enumValues;
  49. length = this.config.length;
  50. constructor(table, config) {
  51. super(table, config);
  52. }
  53. getSQLType() {
  54. return `text${this.config.length ? `(${this.config.length})` : ""}`;
  55. }
  56. }
  57. class SQLiteTextJsonBuilder extends import_common.SQLiteColumnBuilder {
  58. static [import_entity.entityKind] = "SQLiteTextJsonBuilder";
  59. constructor(name) {
  60. super(name, "json", "SQLiteTextJson");
  61. }
  62. /** @internal */
  63. build(table) {
  64. return new SQLiteTextJson(
  65. table,
  66. this.config
  67. );
  68. }
  69. }
  70. class SQLiteTextJson extends import_common.SQLiteColumn {
  71. static [import_entity.entityKind] = "SQLiteTextJson";
  72. getSQLType() {
  73. return "text";
  74. }
  75. mapFromDriverValue(value) {
  76. return JSON.parse(value);
  77. }
  78. mapToDriverValue(value) {
  79. return JSON.stringify(value);
  80. }
  81. }
  82. function text(a, b = {}) {
  83. const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
  84. if (config.mode === "json") {
  85. return new SQLiteTextJsonBuilder(name);
  86. }
  87. return new SQLiteTextBuilder(name, config);
  88. }
  89. // Annotate the CommonJS export names for ESM import in node:
  90. 0 && (module.exports = {
  91. SQLiteText,
  92. SQLiteTextBuilder,
  93. SQLiteTextJson,
  94. SQLiteTextJsonBuilder,
  95. text
  96. });
  97. //# sourceMappingURL=text.cjs.map