table.cjs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 table_exports = {};
  20. __export(table_exports, {
  21. InlineForeignKeys: () => InlineForeignKeys,
  22. SQLiteTable: () => SQLiteTable,
  23. sqliteTable: () => sqliteTable,
  24. sqliteTableCreator: () => sqliteTableCreator
  25. });
  26. module.exports = __toCommonJS(table_exports);
  27. var import_entity = require("../entity.cjs");
  28. var import_table = require("../table.cjs");
  29. var import_all = require("./columns/all.cjs");
  30. const InlineForeignKeys = Symbol.for("drizzle:SQLiteInlineForeignKeys");
  31. class SQLiteTable extends import_table.Table {
  32. static [import_entity.entityKind] = "SQLiteTable";
  33. /** @internal */
  34. static Symbol = Object.assign({}, import_table.Table.Symbol, {
  35. InlineForeignKeys
  36. });
  37. /** @internal */
  38. [import_table.Table.Symbol.Columns];
  39. /** @internal */
  40. [InlineForeignKeys] = [];
  41. /** @internal */
  42. [import_table.Table.Symbol.ExtraConfigBuilder] = void 0;
  43. }
  44. function sqliteTableBase(name, columns, extraConfig, schema, baseName = name) {
  45. const rawTable = new SQLiteTable(name, schema, baseName);
  46. const parsedColumns = typeof columns === "function" ? columns((0, import_all.getSQLiteColumnBuilders)()) : columns;
  47. const builtColumns = Object.fromEntries(
  48. Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
  49. const colBuilder = colBuilderBase;
  50. colBuilder.setName(name2);
  51. const column = colBuilder.build(rawTable);
  52. rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
  53. return [name2, column];
  54. })
  55. );
  56. const table = Object.assign(rawTable, builtColumns);
  57. table[import_table.Table.Symbol.Columns] = builtColumns;
  58. table[import_table.Table.Symbol.ExtraConfigColumns] = builtColumns;
  59. if (extraConfig) {
  60. table[SQLiteTable.Symbol.ExtraConfigBuilder] = extraConfig;
  61. }
  62. return table;
  63. }
  64. const sqliteTable = (name, columns, extraConfig) => {
  65. return sqliteTableBase(name, columns, extraConfig);
  66. };
  67. function sqliteTableCreator(customizeTableName) {
  68. return (name, columns, extraConfig) => {
  69. return sqliteTableBase(customizeTableName(name), columns, extraConfig, void 0, name);
  70. };
  71. }
  72. // Annotate the CommonJS export names for ESM import in node:
  73. 0 && (module.exports = {
  74. InlineForeignKeys,
  75. SQLiteTable,
  76. sqliteTable,
  77. sqliteTableCreator
  78. });
  79. //# sourceMappingURL=table.cjs.map