table.cjs 3.1 KB

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