schema.cjs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 schema_exports = {};
  20. __export(schema_exports, {
  21. GelSchema: () => GelSchema,
  22. gelSchema: () => gelSchema,
  23. isGelSchema: () => isGelSchema
  24. });
  25. module.exports = __toCommonJS(schema_exports);
  26. var import_entity = require("../entity.cjs");
  27. var import_sql = require("../sql/sql.cjs");
  28. var import_sequence = require("./sequence.cjs");
  29. var import_table = require("./table.cjs");
  30. class GelSchema {
  31. constructor(schemaName) {
  32. this.schemaName = schemaName;
  33. }
  34. static [import_entity.entityKind] = "GelSchema";
  35. table = (name, columns, extraConfig) => {
  36. return (0, import_table.gelTableWithSchema)(name, columns, extraConfig, this.schemaName);
  37. };
  38. // view = ((name, columns) => {
  39. // return gelViewWithSchema(name, columns, this.schemaName);
  40. // }) as typeof gelView;
  41. // materializedView = ((name, columns) => {
  42. // return gelMaterializedViewWithSchema(name, columns, this.schemaName);
  43. // }) as typeof gelMaterializedView;
  44. // enum: typeof gelEnum = ((name, values) => {
  45. // return gelEnumWithSchema(name, values, this.schemaName);
  46. // });
  47. sequence = (name, options) => {
  48. return (0, import_sequence.gelSequenceWithSchema)(name, options, this.schemaName);
  49. };
  50. getSQL() {
  51. return new import_sql.SQL([import_sql.sql.identifier(this.schemaName)]);
  52. }
  53. shouldOmitSQLParens() {
  54. return true;
  55. }
  56. }
  57. function isGelSchema(obj) {
  58. return (0, import_entity.is)(obj, GelSchema);
  59. }
  60. function gelSchema(name) {
  61. if (name === "public") {
  62. throw new Error(
  63. `You can't specify 'public' as schema name. Postgres is using public schema by default. If you want to use 'public' schema, just use GelTable() instead of creating a schema`
  64. );
  65. }
  66. return new GelSchema(name);
  67. }
  68. // Annotate the CommonJS export names for ESM import in node:
  69. 0 && (module.exports = {
  70. GelSchema,
  71. gelSchema,
  72. isGelSchema
  73. });
  74. //# sourceMappingURL=schema.cjs.map