CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
session.cjs127 linesDownload Raw Back to singlestore-proxy
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  PreparedQuery: () => PreparedQuery,22  SingleStoreProxyTransaction: () => SingleStoreProxyTransaction,23  SingleStoreRemoteSession: () => SingleStoreRemoteSession24});25module.exports = __toCommonJS(session_exports);26var import_column = require("../column.cjs");27var import_entity = require("../entity.cjs");28var import_logger = require("../logger.cjs");29var import_singlestore_core = require("../singlestore-core/index.cjs");30var import_session = require("../singlestore-core/session.cjs");31var import_sql = require("../sql/sql.cjs");32var import_utils = require("../utils.cjs");33class SingleStoreRemoteSession extends import_session.SingleStoreSession {34  constructor(client, dialect, schema, options) {35    super(dialect);36    this.client = client;37    this.schema = schema;38    this.logger = options.logger ?? new import_logger.NoopLogger();39  }40  static [import_entity.entityKind] = "SingleStoreRemoteSession";41  logger;42  prepareQuery(query, fields, customResultMapper, generatedIds, returningIds) {43    return new PreparedQuery(44      this.client,45      query.sql,46      query.params,47      this.logger,48      fields,49      customResultMapper,50      generatedIds,51      returningIds52    );53  }54  all(query) {55    const querySql = this.dialect.sqlToQuery(query);56    this.logger.logQuery(querySql.sql, querySql.params);57    return this.client(querySql.sql, querySql.params, "all").then(({ rows }) => rows);58  }59  async transaction(_transaction, _config) {60    throw new Error("Transactions are not supported by the SingleStore Proxy driver");61  }62}63class SingleStoreProxyTransaction extends import_singlestore_core.SingleStoreTransaction {64  static [import_entity.entityKind] = "SingleStoreProxyTransaction";65  async transaction(_transaction) {66    throw new Error("Transactions are not supported by the SingleStore Proxy driver");67  }68}69class PreparedQuery extends import_session.SingleStorePreparedQuery {70  constructor(client, queryString, params, logger, fields, customResultMapper, generatedIds, returningIds) {71    super();72    this.client = client;73    this.queryString = queryString;74    this.params = params;75    this.logger = logger;76    this.fields = fields;77    this.customResultMapper = customResultMapper;78    this.generatedIds = generatedIds;79    this.returningIds = returningIds;80  }81  static [import_entity.entityKind] = "SingleStoreProxyPreparedQuery";82  async execute(placeholderValues = {}) {83    const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);84    const { fields, client, queryString, logger, joinsNotNullableMap, customResultMapper, returningIds, generatedIds } = this;85    logger.logQuery(queryString, params);86    if (!fields && !customResultMapper) {87      const { rows: data } = await client(queryString, params, "execute");88      const insertId = data[0].insertId;89      const affectedRows = data[0].affectedRows;90      if (returningIds) {91        const returningResponse = [];92        let j = 0;93        for (let i = insertId; i < insertId + affectedRows; i++) {94          for (const column of returningIds) {95            const key = returningIds[0].path[0];96            if ((0, import_entity.is)(column.field, import_column.Column)) {97              if (column.field.primary && column.field.autoIncrement) {98                returningResponse.push({ [key]: i });99              }100              if (column.field.defaultFn && generatedIds) {101                returningResponse.push({ [key]: generatedIds[j][key] });102              }103            }104          }105          j++;106        }107        return returningResponse;108      }109      return data;110    }111    const { rows } = await client(queryString, params, "all");112    if (customResultMapper) {113      return customResultMapper(rows);114    }115    return rows.map((row) => (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap));116  }117  iterator(_placeholderValues = {}) {118    throw new Error("Streaming is not supported by the SingleStore Proxy driver");119  }120}121// Annotate the CommonJS export names for ESM import in node:1220 && (module.exports = {123  PreparedQuery,124  SingleStoreProxyTransaction,125  SingleStoreRemoteSession126});127//# sourceMappingURL=session.cjs.map