schema.cjs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. PgSchema: () => PgSchema,
  22. isPgSchema: () => isPgSchema,
  23. pgSchema: () => pgSchema
  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_enum = require("./columns/enum.cjs");
  29. var import_sequence = require("./sequence.cjs");
  30. var import_table = require("./table.cjs");
  31. var import_view = require("./view.cjs");
  32. class PgSchema {
  33. constructor(schemaName) {
  34. this.schemaName = schemaName;
  35. }
  36. static [import_entity.entityKind] = "PgSchema";
  37. table = (name, columns, extraConfig) => {
  38. return (0, import_table.pgTableWithSchema)(name, columns, extraConfig, this.schemaName);
  39. };
  40. view = (name, columns) => {
  41. return (0, import_view.pgViewWithSchema)(name, columns, this.schemaName);
  42. };
  43. materializedView = (name, columns) => {
  44. return (0, import_view.pgMaterializedViewWithSchema)(name, columns, this.schemaName);
  45. };
  46. enum(enumName, input) {
  47. return Array.isArray(input) ? (0, import_enum.pgEnumWithSchema)(
  48. enumName,
  49. [...input],
  50. this.schemaName
  51. ) : (0, import_enum.pgEnumObjectWithSchema)(enumName, input, this.schemaName);
  52. }
  53. sequence = (name, options) => {
  54. return (0, import_sequence.pgSequenceWithSchema)(name, options, this.schemaName);
  55. };
  56. getSQL() {
  57. return new import_sql.SQL([import_sql.sql.identifier(this.schemaName)]);
  58. }
  59. shouldOmitSQLParens() {
  60. return true;
  61. }
  62. }
  63. function isPgSchema(obj) {
  64. return (0, import_entity.is)(obj, PgSchema);
  65. }
  66. function pgSchema(name) {
  67. if (name === "public") {
  68. throw new Error(
  69. `You can't specify 'public' as schema name. Postgres is using public schema by default. If you want to use 'public' schema, just use pgTable() instead of creating a schema`
  70. );
  71. }
  72. return new PgSchema(name);
  73. }
  74. // Annotate the CommonJS export names for ESM import in node:
  75. 0 && (module.exports = {
  76. PgSchema,
  77. isPgSchema,
  78. pgSchema
  79. });
  80. //# sourceMappingURL=schema.cjs.map