AK-21/Graphite-Industrial-Intelligence
0
1"use strict";2var __defProp = Object.defineProperty;3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;4var __getOwnPropNames = Object.getOwnPropertyNames;5var __hasOwnProp = Object.prototype.hasOwnProperty;6var __export = (target, all) => {7 for (var name in all)8 __defProp(target, name, { get: all[name], enumerable: true });9};10var __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};18var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);19var session_exports = {};20__export(session_exports, {21 NeonHttpPreparedQuery: () => NeonHttpPreparedQuery,22 NeonHttpSession: () => NeonHttpSession,23 NeonTransaction: () => NeonTransaction24});25module.exports = __toCommonJS(session_exports);26var import_core = require("../cache/core/index.cjs");27var import_entity = require("../entity.cjs");28var import_logger = require("../logger.cjs");29var import_pg_core = require("../pg-core/index.cjs");30var import_session = require("../pg-core/session.cjs");31var import_sql = require("../sql/sql.cjs");32var import_utils = require("../utils.cjs");33const rawQueryConfig = {34 arrayMode: false,35 fullResults: true36};37const queryConfig = {38 arrayMode: true,39 fullResults: true40};41class NeonHttpPreparedQuery extends import_session.PgPreparedQuery {42 constructor(client, query, logger, cache, queryMetadata, cacheConfig, fields, _isResponseInArrayMode, customResultMapper) {43 super(query, cache, queryMetadata, cacheConfig);44 this.client = client;45 this.logger = logger;46 this.fields = fields;47 this._isResponseInArrayMode = _isResponseInArrayMode;48 this.customResultMapper = customResultMapper;49 this.clientQuery = client.query ?? client;50 }51 static [import_entity.entityKind] = "NeonHttpPreparedQuery";52 clientQuery;53 /** @internal */54 async execute(placeholderValues = {}, token = this.authToken) {55 const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues);56 this.logger.logQuery(this.query.sql, params);57 const { fields, clientQuery, query, customResultMapper } = this;58 if (!fields && !customResultMapper) {59 return this.queryWithCache(query.sql, params, async () => {60 return clientQuery(61 query.sql,62 params,63 token === void 0 ? rawQueryConfig : {64 ...rawQueryConfig,65 authToken: token66 }67 );68 });69 }70 const result = await this.queryWithCache(query.sql, params, async () => {71 return await clientQuery(72 query.sql,73 params,74 token === void 0 ? queryConfig : {75 ...queryConfig,76 authToken: token77 }78 );79 });80 return this.mapResult(result);81 }82 mapResult(result) {83 if (!this.fields && !this.customResultMapper) {84 return result;85 }86 const rows = result.rows;87 if (this.customResultMapper) {88 return this.customResultMapper(rows);89 }90 return rows.map((row) => (0, import_utils.mapResultRow)(this.fields, row, this.joinsNotNullableMap));91 }92 all(placeholderValues = {}) {93 const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues);94 this.logger.logQuery(this.query.sql, params);95 return this.clientQuery(96 this.query.sql,97 params,98 this.authToken === void 0 ? rawQueryConfig : {99 ...rawQueryConfig,100 authToken: this.authToken101 }102 ).then((result) => result.rows);103 }104 /** @internal */105 values(placeholderValues = {}, token) {106 const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues);107 this.logger.logQuery(this.query.sql, params);108 return this.clientQuery(this.query.sql, params, { arrayMode: true, fullResults: true, authToken: token }).then((result) => result.rows);109 }110 /** @internal */111 isResponseInArrayMode() {112 return this._isResponseInArrayMode;113 }114}115class NeonHttpSession extends import_session.PgSession {116 constructor(client, dialect, schema, options = {}) {117 super(dialect);118 this.client = client;119 this.schema = schema;120 this.options = options;121 this.clientQuery = client.query ?? client;122 this.logger = options.logger ?? new import_logger.NoopLogger();123 this.cache = options.cache ?? new import_core.NoopCache();124 }125 static [import_entity.entityKind] = "NeonHttpSession";126 clientQuery;127 logger;128 cache;129 prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {130 return new NeonHttpPreparedQuery(131 this.client,132 query,133 this.logger,134 this.cache,135 queryMetadata,136 cacheConfig,137 fields,138 isResponseInArrayMode,139 customResultMapper140 );141 }142 async batch(queries) {143 const preparedQueries = [];144 const builtQueries = [];145 for (const query of queries) {146 const preparedQuery = query._prepare();147 const builtQuery = preparedQuery.getQuery();148 preparedQueries.push(preparedQuery);149 builtQueries.push(150 this.clientQuery(builtQuery.sql, builtQuery.params, {151 fullResults: true,152 arrayMode: preparedQuery.isResponseInArrayMode()153 })154 );155 }156 const batchResults = await this.client.transaction(builtQueries, queryConfig);157 return batchResults.map((result, i) => preparedQueries[i].mapResult(result, true));158 }159 // change return type to QueryRows<true>160 async query(query, params) {161 this.logger.logQuery(query, params);162 const result = await this.clientQuery(query, params, { arrayMode: true, fullResults: true });163 return result;164 }165 // change return type to QueryRows<false>166 async queryObjects(query, params) {167 return this.clientQuery(query, params, { arrayMode: false, fullResults: true });168 }169 /** @internal */170 async count(sql, token) {171 const res = await this.execute(sql, token);172 return Number(173 res["rows"][0]["count"]174 );175 }176 async transaction(_transaction, _config = {}) {177 throw new Error("No transactions support in neon-http driver");178 }179}180class NeonTransaction extends import_pg_core.PgTransaction {181 static [import_entity.entityKind] = "NeonHttpTransaction";182 async transaction(_transaction) {183 throw new Error("No transactions support in neon-http driver");184 }185}186// Annotate the CommonJS export names for ESM import in node:1870 && (module.exports = {188 NeonHttpPreparedQuery,189 NeonHttpSession,190 NeonTransaction191});192//# sourceMappingURL=session.cjs.map