session.cjs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 session_exports = {};
  20. __export(session_exports, {
  21. PgProxyTransaction: () => PgProxyTransaction,
  22. PgRemoteSession: () => PgRemoteSession,
  23. PreparedQuery: () => PreparedQuery
  24. });
  25. module.exports = __toCommonJS(session_exports);
  26. var import_cache = require("../cache/core/cache.cjs");
  27. var import_entity = require("../entity.cjs");
  28. var import_logger = require("../logger.cjs");
  29. var import_pg_core = require("../pg-core/index.cjs");
  30. var import_session = require("../pg-core/session.cjs");
  31. var import_sql = require("../sql/sql.cjs");
  32. var import_tracing = require("../tracing.cjs");
  33. var import_utils = require("../utils.cjs");
  34. class PgRemoteSession extends import_session.PgSession {
  35. constructor(client, dialect, schema, options = {}) {
  36. super(dialect);
  37. this.client = client;
  38. this.schema = schema;
  39. this.logger = options.logger ?? new import_logger.NoopLogger();
  40. this.cache = options.cache ?? new import_cache.NoopCache();
  41. }
  42. static [import_entity.entityKind] = "PgRemoteSession";
  43. logger;
  44. cache;
  45. prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
  46. return new PreparedQuery(
  47. this.client,
  48. query.sql,
  49. query.params,
  50. query.typings,
  51. this.logger,
  52. this.cache,
  53. queryMetadata,
  54. cacheConfig,
  55. fields,
  56. isResponseInArrayMode,
  57. customResultMapper
  58. );
  59. }
  60. async transaction(_transaction, _config) {
  61. throw new Error("Transactions are not supported by the Postgres Proxy driver");
  62. }
  63. }
  64. class PgProxyTransaction extends import_pg_core.PgTransaction {
  65. static [import_entity.entityKind] = "PgProxyTransaction";
  66. async transaction(_transaction) {
  67. throw new Error("Transactions are not supported by the Postgres Proxy driver");
  68. }
  69. }
  70. class PreparedQuery extends import_session.PgPreparedQuery {
  71. constructor(client, queryString, params, typings, logger, cache, queryMetadata, cacheConfig, fields, _isResponseInArrayMode, customResultMapper) {
  72. super({ sql: queryString, params }, cache, queryMetadata, cacheConfig);
  73. this.client = client;
  74. this.queryString = queryString;
  75. this.params = params;
  76. this.typings = typings;
  77. this.logger = logger;
  78. this.fields = fields;
  79. this._isResponseInArrayMode = _isResponseInArrayMode;
  80. this.customResultMapper = customResultMapper;
  81. }
  82. static [import_entity.entityKind] = "PgProxyPreparedQuery";
  83. async execute(placeholderValues = {}) {
  84. return import_tracing.tracer.startActiveSpan("drizzle.execute", async (span) => {
  85. const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);
  86. const { fields, client, queryString, joinsNotNullableMap, customResultMapper, logger, typings } = this;
  87. span?.setAttributes({
  88. "drizzle.query.text": queryString,
  89. "drizzle.query.params": JSON.stringify(params)
  90. });
  91. logger.logQuery(queryString, params);
  92. if (!fields && !customResultMapper) {
  93. return import_tracing.tracer.startActiveSpan("drizzle.driver.execute", async () => {
  94. const { rows: rows2 } = await this.queryWithCache(queryString, params, async () => {
  95. return await client(queryString, params, "execute", typings);
  96. });
  97. return rows2;
  98. });
  99. }
  100. const rows = await import_tracing.tracer.startActiveSpan("drizzle.driver.execute", async () => {
  101. span?.setAttributes({
  102. "drizzle.query.text": queryString,
  103. "drizzle.query.params": JSON.stringify(params)
  104. });
  105. const { rows: rows2 } = await this.queryWithCache(queryString, params, async () => {
  106. return await client(queryString, params, "all", typings);
  107. });
  108. return rows2;
  109. });
  110. return import_tracing.tracer.startActiveSpan("drizzle.mapResponse", () => {
  111. return customResultMapper ? customResultMapper(rows) : rows.map((row) => (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap));
  112. });
  113. });
  114. }
  115. async all() {
  116. }
  117. /** @internal */
  118. isResponseInArrayMode() {
  119. return this._isResponseInArrayMode;
  120. }
  121. }
  122. // Annotate the CommonJS export names for ESM import in node:
  123. 0 && (module.exports = {
  124. PgProxyTransaction,
  125. PgRemoteSession,
  126. PreparedQuery
  127. });
  128. //# sourceMappingURL=session.cjs.map