utils.cjs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 utils_exports = {};
  20. __export(utils_exports, {
  21. extractUsedTable: () => extractUsedTable,
  22. getTableConfig: () => getTableConfig
  23. });
  24. module.exports = __toCommonJS(utils_exports);
  25. var import_entity = require("../entity.cjs");
  26. var import_sql = require("../sql/sql.cjs");
  27. var import_subquery = require("../subquery.cjs");
  28. var import_table = require("../table.cjs");
  29. var import_indexes = require("./indexes.cjs");
  30. var import_primary_keys = require("./primary-keys.cjs");
  31. var import_table2 = require("./table.cjs");
  32. var import_unique_constraint = require("./unique-constraint.cjs");
  33. function extractUsedTable(table) {
  34. if ((0, import_entity.is)(table, import_table2.SingleStoreTable)) {
  35. return [`${table[import_table.Table.Symbol.BaseName]}`];
  36. }
  37. if ((0, import_entity.is)(table, import_subquery.Subquery)) {
  38. return table._.usedTables ?? [];
  39. }
  40. if ((0, import_entity.is)(table, import_sql.SQL)) {
  41. return table.usedTables ?? [];
  42. }
  43. return [];
  44. }
  45. function getTableConfig(table) {
  46. const columns = Object.values(table[import_table2.SingleStoreTable.Symbol.Columns]);
  47. const indexes = [];
  48. const primaryKeys = [];
  49. const uniqueConstraints = [];
  50. const name = table[import_table.Table.Symbol.Name];
  51. const schema = table[import_table.Table.Symbol.Schema];
  52. const baseName = table[import_table.Table.Symbol.BaseName];
  53. const extraConfigBuilder = table[import_table2.SingleStoreTable.Symbol.ExtraConfigBuilder];
  54. if (extraConfigBuilder !== void 0) {
  55. const extraConfig = extraConfigBuilder(table[import_table2.SingleStoreTable.Symbol.Columns]);
  56. const extraValues = Array.isArray(extraConfig) ? extraConfig.flat(1) : Object.values(extraConfig);
  57. for (const builder of Object.values(extraValues)) {
  58. if ((0, import_entity.is)(builder, import_indexes.IndexBuilder)) {
  59. indexes.push(builder.build(table));
  60. } else if ((0, import_entity.is)(builder, import_unique_constraint.UniqueConstraintBuilder)) {
  61. uniqueConstraints.push(builder.build(table));
  62. } else if ((0, import_entity.is)(builder, import_primary_keys.PrimaryKeyBuilder)) {
  63. primaryKeys.push(builder.build(table));
  64. }
  65. }
  66. }
  67. return {
  68. columns,
  69. indexes,
  70. primaryKeys,
  71. uniqueConstraints,
  72. name,
  73. schema,
  74. baseName
  75. };
  76. }
  77. // Annotate the CommonJS export names for ESM import in node:
  78. 0 && (module.exports = {
  79. extractUsedTable,
  80. getTableConfig
  81. });
  82. //# sourceMappingURL=utils.cjs.map