common.cjs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 common_exports = {};
  20. __export(common_exports, {
  21. SQLiteColumn: () => SQLiteColumn,
  22. SQLiteColumnBuilder: () => SQLiteColumnBuilder
  23. });
  24. module.exports = __toCommonJS(common_exports);
  25. var import_column_builder = require("../../column-builder.cjs");
  26. var import_column = require("../../column.cjs");
  27. var import_entity = require("../../entity.cjs");
  28. var import_foreign_keys = require("../foreign-keys.cjs");
  29. var import_unique_constraint = require("../unique-constraint.cjs");
  30. class SQLiteColumnBuilder extends import_column_builder.ColumnBuilder {
  31. static [import_entity.entityKind] = "SQLiteColumnBuilder";
  32. foreignKeyConfigs = [];
  33. references(ref, actions = {}) {
  34. this.foreignKeyConfigs.push({ ref, actions });
  35. return this;
  36. }
  37. unique(name) {
  38. this.config.isUnique = true;
  39. this.config.uniqueName = name;
  40. return this;
  41. }
  42. generatedAlwaysAs(as, config) {
  43. this.config.generated = {
  44. as,
  45. type: "always",
  46. mode: config?.mode ?? "virtual"
  47. };
  48. return this;
  49. }
  50. /** @internal */
  51. buildForeignKeys(column, table) {
  52. return this.foreignKeyConfigs.map(({ ref, actions }) => {
  53. return ((ref2, actions2) => {
  54. const builder = new import_foreign_keys.ForeignKeyBuilder(() => {
  55. const foreignColumn = ref2();
  56. return { columns: [column], foreignColumns: [foreignColumn] };
  57. });
  58. if (actions2.onUpdate) {
  59. builder.onUpdate(actions2.onUpdate);
  60. }
  61. if (actions2.onDelete) {
  62. builder.onDelete(actions2.onDelete);
  63. }
  64. return builder.build(table);
  65. })(ref, actions);
  66. });
  67. }
  68. }
  69. class SQLiteColumn extends import_column.Column {
  70. constructor(table, config) {
  71. if (!config.uniqueName) {
  72. config.uniqueName = (0, import_unique_constraint.uniqueKeyName)(table, [config.name]);
  73. }
  74. super(table, config);
  75. this.table = table;
  76. }
  77. static [import_entity.entityKind] = "SQLiteColumn";
  78. }
  79. // Annotate the CommonJS export names for ESM import in node:
  80. 0 && (module.exports = {
  81. SQLiteColumn,
  82. SQLiteColumnBuilder
  83. });
  84. //# sourceMappingURL=common.cjs.map