CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
driver.cjs120 linesDownload Raw Back to node-postgres
1"use strict";2var __create = Object.create;3var __defProp = Object.defineProperty;4var __getOwnPropDesc = Object.getOwnPropertyDescriptor;5var __getOwnPropNames = Object.getOwnPropertyNames;6var __getProtoOf = Object.getPrototypeOf;7var __hasOwnProp = Object.prototype.hasOwnProperty;8var __export = (target, all) => {9  for (var name in all)10    __defProp(target, name, { get: all[name], enumerable: true });11};12var __copyProps = (to, from, except, desc) => {13  if (from && typeof from === "object" || typeof from === "function") {14    for (let key of __getOwnPropNames(from))15      if (!__hasOwnProp.call(to, key) && key !== except)16        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });17  }18  return to;19};20var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(21  // If the importer is in node compatibility mode or this is not an ESM22  // file that has been converted to a CommonJS file using a Babel-23  // compatible transform (i.e. "__esModule" has not been set), then set24  // "default" to the CommonJS "module.exports" for node compatibility.25  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,26  mod27));28var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);29var driver_exports = {};30__export(driver_exports, {31  NodePgDatabase: () => NodePgDatabase,32  NodePgDriver: () => NodePgDriver,33  drizzle: () => drizzle34});35module.exports = __toCommonJS(driver_exports);36var import_pg = __toESM(require("pg"), 1);37var import_entity = require("../entity.cjs");38var import_logger = require("../logger.cjs");39var import_db = require("../pg-core/db.cjs");40var import_dialect = require("../pg-core/dialect.cjs");41var import_relations = require("../relations.cjs");42var import_utils = require("../utils.cjs");43var import_session = require("./session.cjs");44class NodePgDriver {45  constructor(client, dialect, options = {}) {46    this.client = client;47    this.dialect = dialect;48    this.options = options;49  }50  static [import_entity.entityKind] = "NodePgDriver";51  createSession(schema) {52    return new import_session.NodePgSession(this.client, this.dialect, schema, {53      logger: this.options.logger,54      cache: this.options.cache55    });56  }57}58class NodePgDatabase extends import_db.PgDatabase {59  static [import_entity.entityKind] = "NodePgDatabase";60}61function construct(client, config = {}) {62  const dialect = new import_dialect.PgDialect({ casing: config.casing });63  let logger;64  if (config.logger === true) {65    logger = new import_logger.DefaultLogger();66  } else if (config.logger !== false) {67    logger = config.logger;68  }69  let schema;70  if (config.schema) {71    const tablesConfig = (0, import_relations.extractTablesRelationalConfig)(72      config.schema,73      import_relations.createTableRelationsHelpers74    );75    schema = {76      fullSchema: config.schema,77      schema: tablesConfig.tables,78      tableNamesMap: tablesConfig.tableNamesMap79    };80  }81  const driver = new NodePgDriver(client, dialect, { logger, cache: config.cache });82  const session = driver.createSession(schema);83  const db = new NodePgDatabase(dialect, session, schema);84  db.$client = client;85  db.$cache = config.cache;86  if (db.$cache) {87    db.$cache["invalidate"] = config.cache?.onMutate;88  }89  return db;90}91function drizzle(...params) {92  if (typeof params[0] === "string") {93    const instance = new import_pg.default.Pool({94      connectionString: params[0]95    });96    return construct(instance, params[1]);97  }98  if ((0, import_utils.isConfig)(params[0])) {99    const { connection, client, ...drizzleConfig } = params[0];100    if (client) return construct(client, drizzleConfig);101    const instance = typeof connection === "string" ? new import_pg.default.Pool({102      connectionString: connection103    }) : new import_pg.default.Pool(connection);104    return construct(instance, drizzleConfig);105  }106  return construct(params[0], params[1]);107}108((drizzle2) => {109  function mock(config) {110    return construct({}, config);111  }112  drizzle2.mock = mock;113})(drizzle || (drizzle = {}));114// Annotate the CommonJS export names for ESM import in node:1150 && (module.exports = {116  NodePgDatabase,117  NodePgDriver,118  drizzle119});120//# sourceMappingURL=driver.cjs.map