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 MySqlProxyTransaction: () => MySqlProxyTransaction,22 MySqlRemoteSession: () => MySqlRemoteSession,23 PreparedQuery: () => PreparedQuery24});25module.exports = __toCommonJS(session_exports);26var import_core = require("../cache/core/index.cjs");27var import_column = require("../column.cjs");28var import_entity = require("../entity.cjs");29var import_logger = require("../logger.cjs");30var import_mysql_core = require("../mysql-core/index.cjs");31var import_session = require("../mysql-core/session.cjs");32var import_sql = require("../sql/sql.cjs");33var import_utils = require("../utils.cjs");34class MySqlRemoteSession extends import_session.MySqlSession {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_core.NoopCache();41 }42 static [import_entity.entityKind] = "MySqlRemoteSession";43 logger;44 cache;45 prepareQuery(query, fields, customResultMapper, generatedIds, returningIds, queryMetadata, cacheConfig) {46 return new PreparedQuery(47 this.client,48 query.sql,49 query.params,50 this.logger,51 this.cache,52 queryMetadata,53 cacheConfig,54 fields,55 customResultMapper,56 generatedIds,57 returningIds58 );59 }60 all(query) {61 const querySql = this.dialect.sqlToQuery(query);62 this.logger.logQuery(querySql.sql, querySql.params);63 return this.client(querySql.sql, querySql.params, "all").then(({ rows }) => rows);64 }65 async transaction(_transaction, _config) {66 throw new Error("Transactions are not supported by the MySql Proxy driver");67 }68}69class MySqlProxyTransaction extends import_mysql_core.MySqlTransaction {70 static [import_entity.entityKind] = "MySqlProxyTransaction";71 async transaction(_transaction) {72 throw new Error("Transactions are not supported by the MySql Proxy driver");73 }74}75class PreparedQuery extends import_session.MySqlPreparedQuery {76 constructor(client, queryString, params, logger, cache, queryMetadata, cacheConfig, fields, customResultMapper, generatedIds, returningIds) {77 super(cache, queryMetadata, cacheConfig);78 this.client = client;79 this.queryString = queryString;80 this.params = params;81 this.logger = logger;82 this.fields = fields;83 this.customResultMapper = customResultMapper;84 this.generatedIds = generatedIds;85 this.returningIds = returningIds;86 }87 static [import_entity.entityKind] = "MySqlProxyPreparedQuery";88 async execute(placeholderValues = {}) {89 const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);90 const { fields, client, queryString, logger, joinsNotNullableMap, customResultMapper, returningIds, generatedIds } = this;91 logger.logQuery(queryString, params);92 if (!fields && !customResultMapper) {93 const { rows: data } = await this.queryWithCache(queryString, params, async () => {94 return await client(queryString, params, "execute");95 });96 const insertId = data[0].insertId;97 const affectedRows = data[0].affectedRows;98 if (returningIds) {99 const returningResponse = [];100 let j = 0;101 for (let i = insertId; i < insertId + affectedRows; i++) {102 for (const column of returningIds) {103 const key = returningIds[0].path[0];104 if ((0, import_entity.is)(column.field, import_column.Column)) {105 if (column.field.primary && column.field.autoIncrement) {106 returningResponse.push({ [key]: i });107 }108 if (column.field.defaultFn && generatedIds) {109 returningResponse.push({ [key]: generatedIds[j][key] });110 }111 }112 }113 j++;114 }115 return returningResponse;116 }117 return data;118 }119 const { rows } = await this.queryWithCache(queryString, params, async () => {120 return await client(queryString, params, "all");121 });122 if (customResultMapper) {123 return customResultMapper(rows);124 }125 return rows.map((row) => (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap));126 }127 iterator(_placeholderValues = {}) {128 throw new Error("Streaming is not supported by the MySql Proxy driver");129 }130}131// Annotate the CommonJS export names for ESM import in node:1320 && (module.exports = {133 MySqlProxyTransaction,134 MySqlRemoteSession,135 PreparedQuery136});137//# sourceMappingURL=session.cjs.map