Initial commit

This commit is contained in:
Ammaar Reshi
2025-01-04 14:06:53 +00:00
parent 7082408604
commit d6025af146
23760 changed files with 3299690 additions and 0 deletions

114
node_modules/drizzle-orm/node-postgres/driver.cjs generated vendored Normal file
View File

@ -0,0 +1,114 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var driver_exports = {};
__export(driver_exports, {
NodePgDatabase: () => NodePgDatabase,
NodePgDriver: () => NodePgDriver,
drizzle: () => drizzle
});
module.exports = __toCommonJS(driver_exports);
var import_pg = __toESM(require("pg"), 1);
var import_entity = require("../entity.cjs");
var import_logger = require("../logger.cjs");
var import_db = require("../pg-core/db.cjs");
var import_dialect = require("../pg-core/dialect.cjs");
var import_relations = require("../relations.cjs");
var import_utils = require("../utils.cjs");
var import_session = require("./session.cjs");
class NodePgDriver {
constructor(client, dialect, options = {}) {
this.client = client;
this.dialect = dialect;
this.options = options;
}
static [import_entity.entityKind] = "NodePgDriver";
createSession(schema) {
return new import_session.NodePgSession(this.client, this.dialect, schema, { logger: this.options.logger });
}
}
class NodePgDatabase extends import_db.PgDatabase {
static [import_entity.entityKind] = "NodePgDatabase";
}
function construct(client, config = {}) {
const dialect = new import_dialect.PgDialect({ casing: config.casing });
let logger;
if (config.logger === true) {
logger = new import_logger.DefaultLogger();
} else if (config.logger !== false) {
logger = config.logger;
}
let schema;
if (config.schema) {
const tablesConfig = (0, import_relations.extractTablesRelationalConfig)(
config.schema,
import_relations.createTableRelationsHelpers
);
schema = {
fullSchema: config.schema,
schema: tablesConfig.tables,
tableNamesMap: tablesConfig.tableNamesMap
};
}
const driver = new NodePgDriver(client, dialect, { logger });
const session = driver.createSession(schema);
const db = new NodePgDatabase(dialect, session, schema);
db.$client = client;
return db;
}
function drizzle(...params) {
if (typeof params[0] === "string") {
const instance = new import_pg.default.Pool({
connectionString: params[0]
});
return construct(instance, params[1]);
}
if ((0, import_utils.isConfig)(params[0])) {
const { connection, client, ...drizzleConfig } = params[0];
if (client)
return construct(client, drizzleConfig);
const instance = typeof connection === "string" ? new import_pg.default.Pool({
connectionString: connection
}) : new import_pg.default.Pool(connection);
return construct(instance, drizzleConfig);
}
return construct(params[0], params[1]);
}
((drizzle2) => {
function mock(config) {
return construct({}, config);
}
drizzle2.mock = mock;
})(drizzle || (drizzle = {}));
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
NodePgDatabase,
NodePgDriver,
drizzle
});
//# sourceMappingURL=driver.cjs.map

File diff suppressed because one or more lines are too long

42
node_modules/drizzle-orm/node-postgres/driver.d.cts generated vendored Normal file
View File

@ -0,0 +1,42 @@
import { type Pool, type PoolConfig } from 'pg';
import { entityKind } from "../entity.cjs";
import type { Logger } from "../logger.cjs";
import { PgDatabase } from "../pg-core/db.cjs";
import { PgDialect } from "../pg-core/dialect.cjs";
import { type RelationalSchemaConfig, type TablesRelationalConfig } from "../relations.cjs";
import { type DrizzleConfig } from "../utils.cjs";
import type { NodePgClient, NodePgQueryResultHKT } from "./session.cjs";
import { NodePgSession } from "./session.cjs";
export interface PgDriverOptions {
logger?: Logger;
}
export declare class NodePgDriver {
private client;
private dialect;
private options;
static readonly [entityKind]: string;
constructor(client: NodePgClient, dialect: PgDialect, options?: PgDriverOptions);
createSession(schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined): NodePgSession<Record<string, unknown>, TablesRelationalConfig>;
}
export declare class NodePgDatabase<TSchema extends Record<string, unknown> = Record<string, never>> extends PgDatabase<NodePgQueryResultHKT, TSchema> {
static readonly [entityKind]: string;
}
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends NodePgClient = Pool>(...params: [
TClient | string
] | [
TClient | string,
DrizzleConfig<TSchema>
] | [
(DrizzleConfig<TSchema> & ({
connection: string | PoolConfig;
} | {
client: TClient;
}))
]): NodePgDatabase<TSchema> & {
$client: TClient;
};
export declare namespace drizzle {
function mock<TSchema extends Record<string, unknown> = Record<string, never>>(config?: DrizzleConfig<TSchema>): NodePgDatabase<TSchema> & {
$client: '$client is not available on drizzle.mock()';
};
}

42
node_modules/drizzle-orm/node-postgres/driver.d.ts generated vendored Normal file
View File

@ -0,0 +1,42 @@
import { type Pool, type PoolConfig } from 'pg';
import { entityKind } from "../entity.js";
import type { Logger } from "../logger.js";
import { PgDatabase } from "../pg-core/db.js";
import { PgDialect } from "../pg-core/dialect.js";
import { type RelationalSchemaConfig, type TablesRelationalConfig } from "../relations.js";
import { type DrizzleConfig } from "../utils.js";
import type { NodePgClient, NodePgQueryResultHKT } from "./session.js";
import { NodePgSession } from "./session.js";
export interface PgDriverOptions {
logger?: Logger;
}
export declare class NodePgDriver {
private client;
private dialect;
private options;
static readonly [entityKind]: string;
constructor(client: NodePgClient, dialect: PgDialect, options?: PgDriverOptions);
createSession(schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined): NodePgSession<Record<string, unknown>, TablesRelationalConfig>;
}
export declare class NodePgDatabase<TSchema extends Record<string, unknown> = Record<string, never>> extends PgDatabase<NodePgQueryResultHKT, TSchema> {
static readonly [entityKind]: string;
}
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends NodePgClient = Pool>(...params: [
TClient | string
] | [
TClient | string,
DrizzleConfig<TSchema>
] | [
(DrizzleConfig<TSchema> & ({
connection: string | PoolConfig;
} | {
client: TClient;
}))
]): NodePgDatabase<TSchema> & {
$client: TClient;
};
export declare namespace drizzle {
function mock<TSchema extends Record<string, unknown> = Record<string, never>>(config?: DrizzleConfig<TSchema>): NodePgDatabase<TSchema> & {
$client: '$client is not available on drizzle.mock()';
};
}

81
node_modules/drizzle-orm/node-postgres/driver.js generated vendored Normal file
View File

@ -0,0 +1,81 @@
import pg from "pg";
import { entityKind } from "../entity.js";
import { DefaultLogger } from "../logger.js";
import { PgDatabase } from "../pg-core/db.js";
import { PgDialect } from "../pg-core/dialect.js";
import {
createTableRelationsHelpers,
extractTablesRelationalConfig
} from "../relations.js";
import { isConfig } from "../utils.js";
import { NodePgSession } from "./session.js";
class NodePgDriver {
constructor(client, dialect, options = {}) {
this.client = client;
this.dialect = dialect;
this.options = options;
}
static [entityKind] = "NodePgDriver";
createSession(schema) {
return new NodePgSession(this.client, this.dialect, schema, { logger: this.options.logger });
}
}
class NodePgDatabase extends PgDatabase {
static [entityKind] = "NodePgDatabase";
}
function construct(client, config = {}) {
const dialect = new PgDialect({ casing: config.casing });
let logger;
if (config.logger === true) {
logger = new DefaultLogger();
} else if (config.logger !== false) {
logger = config.logger;
}
let schema;
if (config.schema) {
const tablesConfig = extractTablesRelationalConfig(
config.schema,
createTableRelationsHelpers
);
schema = {
fullSchema: config.schema,
schema: tablesConfig.tables,
tableNamesMap: tablesConfig.tableNamesMap
};
}
const driver = new NodePgDriver(client, dialect, { logger });
const session = driver.createSession(schema);
const db = new NodePgDatabase(dialect, session, schema);
db.$client = client;
return db;
}
function drizzle(...params) {
if (typeof params[0] === "string") {
const instance = new pg.Pool({
connectionString: params[0]
});
return construct(instance, params[1]);
}
if (isConfig(params[0])) {
const { connection, client, ...drizzleConfig } = params[0];
if (client)
return construct(client, drizzleConfig);
const instance = typeof connection === "string" ? new pg.Pool({
connectionString: connection
}) : new pg.Pool(connection);
return construct(instance, drizzleConfig);
}
return construct(params[0], params[1]);
}
((drizzle2) => {
function mock(config) {
return construct({}, config);
}
drizzle2.mock = mock;
})(drizzle || (drizzle = {}));
export {
NodePgDatabase,
NodePgDriver,
drizzle
};
//# sourceMappingURL=driver.js.map

1
node_modules/drizzle-orm/node-postgres/driver.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

25
node_modules/drizzle-orm/node-postgres/index.cjs generated vendored Normal file
View File

@ -0,0 +1,25 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var node_postgres_exports = {};
module.exports = __toCommonJS(node_postgres_exports);
__reExport(node_postgres_exports, require("./driver.cjs"), module.exports);
__reExport(node_postgres_exports, require("./session.cjs"), module.exports);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
...require("./driver.cjs"),
...require("./session.cjs")
});
//# sourceMappingURL=index.cjs.map

1
node_modules/drizzle-orm/node-postgres/index.cjs.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/node-postgres/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,kCAAc,wBAAd;AACA,kCAAc,yBADd;","names":[]}

2
node_modules/drizzle-orm/node-postgres/index.d.cts generated vendored Normal file
View File

@ -0,0 +1,2 @@
export * from "./driver.cjs";
export * from "./session.cjs";

2
node_modules/drizzle-orm/node-postgres/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,2 @@
export * from "./driver.js";
export * from "./session.js";

3
node_modules/drizzle-orm/node-postgres/index.js generated vendored Normal file
View File

@ -0,0 +1,3 @@
export * from "./driver.js";
export * from "./session.js";
//# sourceMappingURL=index.js.map

1
node_modules/drizzle-orm/node-postgres/index.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/node-postgres/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}

33
node_modules/drizzle-orm/node-postgres/migrator.cjs generated vendored Normal file
View File

@ -0,0 +1,33 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var migrator_exports = {};
__export(migrator_exports, {
migrate: () => migrate
});
module.exports = __toCommonJS(migrator_exports);
var import_migrator = require("../migrator.cjs");
async function migrate(db, config) {
const migrations = (0, import_migrator.readMigrationFiles)(config);
await db.dialect.migrate(migrations, db.session, config);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
migrate
});
//# sourceMappingURL=migrator.cjs.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/node-postgres/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type { NodePgDatabase } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: NodePgDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tawait db.dialect.migrate(migrations, db.session, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAmC;AAGnC,eAAsB,QACrB,IACA,QACC;AACD,QAAM,iBAAa,oCAAmB,MAAM;AAC5C,QAAM,GAAG,QAAQ,QAAQ,YAAY,GAAG,SAAS,MAAM;AACxD;","names":[]}

View File

@ -0,0 +1,3 @@
import type { MigrationConfig } from "../migrator.cjs";
import type { NodePgDatabase } from "./driver.cjs";
export declare function migrate<TSchema extends Record<string, unknown>>(db: NodePgDatabase<TSchema>, config: MigrationConfig): Promise<void>;

3
node_modules/drizzle-orm/node-postgres/migrator.d.ts generated vendored Normal file
View File

@ -0,0 +1,3 @@
import type { MigrationConfig } from "../migrator.js";
import type { NodePgDatabase } from "./driver.js";
export declare function migrate<TSchema extends Record<string, unknown>>(db: NodePgDatabase<TSchema>, config: MigrationConfig): Promise<void>;

9
node_modules/drizzle-orm/node-postgres/migrator.js generated vendored Normal file
View File

@ -0,0 +1,9 @@
import { readMigrationFiles } from "../migrator.js";
async function migrate(db, config) {
const migrations = readMigrationFiles(config);
await db.dialect.migrate(migrations, db.session, config);
}
export {
migrate
};
//# sourceMappingURL=migrator.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/node-postgres/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type { NodePgDatabase } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: NodePgDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tawait db.dialect.migrate(migrations, db.session, config);\n}\n"],"mappings":"AACA,SAAS,0BAA0B;AAGnC,eAAsB,QACrB,IACA,QACC;AACD,QAAM,aAAa,mBAAmB,MAAM;AAC5C,QAAM,GAAG,QAAQ,QAAQ,YAAY,GAAG,SAAS,MAAM;AACxD;","names":[]}

223
node_modules/drizzle-orm/node-postgres/session.cjs generated vendored Normal file
View File

@ -0,0 +1,223 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var session_exports = {};
__export(session_exports, {
NodePgPreparedQuery: () => NodePgPreparedQuery,
NodePgSession: () => NodePgSession,
NodePgTransaction: () => NodePgTransaction
});
module.exports = __toCommonJS(session_exports);
var import_pg = __toESM(require("pg"), 1);
var import_entity = require("../entity.cjs");
var import_logger = require("../logger.cjs");
var import_pg_core = require("../pg-core/index.cjs");
var import_session = require("../pg-core/session.cjs");
var import_sql = require("../sql/sql.cjs");
var import_tracing = require("../tracing.cjs");
var import_utils = require("../utils.cjs");
const { Pool, types } = import_pg.default;
class NodePgPreparedQuery extends import_session.PgPreparedQuery {
constructor(client, queryString, params, logger, fields, name, _isResponseInArrayMode, customResultMapper) {
super({ sql: queryString, params });
this.client = client;
this.params = params;
this.logger = logger;
this.fields = fields;
this._isResponseInArrayMode = _isResponseInArrayMode;
this.customResultMapper = customResultMapper;
this.rawQueryConfig = {
name,
text: queryString,
types: {
// @ts-ignore
getTypeParser: (typeId, format) => {
if (typeId === types.builtins.TIMESTAMPTZ) {
return (val) => val;
}
if (typeId === types.builtins.TIMESTAMP) {
return (val) => val;
}
if (typeId === types.builtins.DATE) {
return (val) => val;
}
if (typeId === types.builtins.INTERVAL) {
return (val) => val;
}
return types.getTypeParser(typeId, format);
}
}
};
this.queryConfig = {
name,
text: queryString,
rowMode: "array",
types: {
// @ts-ignore
getTypeParser: (typeId, format) => {
if (typeId === types.builtins.TIMESTAMPTZ) {
return (val) => val;
}
if (typeId === types.builtins.TIMESTAMP) {
return (val) => val;
}
if (typeId === types.builtins.DATE) {
return (val) => val;
}
if (typeId === types.builtins.INTERVAL) {
return (val) => val;
}
return types.getTypeParser(typeId, format);
}
}
};
}
static [import_entity.entityKind] = "NodePgPreparedQuery";
rawQueryConfig;
queryConfig;
async execute(placeholderValues = {}) {
return import_tracing.tracer.startActiveSpan("drizzle.execute", async () => {
const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);
this.logger.logQuery(this.rawQueryConfig.text, params);
const { fields, rawQueryConfig: rawQuery, client, queryConfig: query, joinsNotNullableMap, customResultMapper } = this;
if (!fields && !customResultMapper) {
return import_tracing.tracer.startActiveSpan("drizzle.driver.execute", async (span) => {
span?.setAttributes({
"drizzle.query.name": rawQuery.name,
"drizzle.query.text": rawQuery.text,
"drizzle.query.params": JSON.stringify(params)
});
return client.query(rawQuery, params);
});
}
const result = await import_tracing.tracer.startActiveSpan("drizzle.driver.execute", (span) => {
span?.setAttributes({
"drizzle.query.name": query.name,
"drizzle.query.text": query.text,
"drizzle.query.params": JSON.stringify(params)
});
return client.query(query, params);
});
return import_tracing.tracer.startActiveSpan("drizzle.mapResponse", () => {
return customResultMapper ? customResultMapper(result.rows) : result.rows.map((row) => (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap));
});
});
}
all(placeholderValues = {}) {
return import_tracing.tracer.startActiveSpan("drizzle.execute", () => {
const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);
this.logger.logQuery(this.rawQueryConfig.text, params);
return import_tracing.tracer.startActiveSpan("drizzle.driver.execute", (span) => {
span?.setAttributes({
"drizzle.query.name": this.rawQueryConfig.name,
"drizzle.query.text": this.rawQueryConfig.text,
"drizzle.query.params": JSON.stringify(params)
});
return this.client.query(this.rawQueryConfig, params).then((result) => result.rows);
});
});
}
/** @internal */
isResponseInArrayMode() {
return this._isResponseInArrayMode;
}
}
class NodePgSession extends import_session.PgSession {
constructor(client, dialect, schema, options = {}) {
super(dialect);
this.client = client;
this.schema = schema;
this.options = options;
this.logger = options.logger ?? new import_logger.NoopLogger();
}
static [import_entity.entityKind] = "NodePgSession";
logger;
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper) {
return new NodePgPreparedQuery(
this.client,
query.sql,
query.params,
this.logger,
fields,
name,
isResponseInArrayMode,
customResultMapper
);
}
async transaction(transaction, config) {
const session = this.client instanceof Pool ? new NodePgSession(await this.client.connect(), this.dialect, this.schema, this.options) : this;
const tx = new NodePgTransaction(this.dialect, session, this.schema);
await tx.execute(import_sql.sql`begin${config ? import_sql.sql` ${tx.getTransactionConfigSQL(config)}` : void 0}`);
try {
const result = await transaction(tx);
await tx.execute(import_sql.sql`commit`);
return result;
} catch (error) {
await tx.execute(import_sql.sql`rollback`);
throw error;
} finally {
if (this.client instanceof Pool) {
session.client.release();
}
}
}
async count(sql2) {
const res = await this.execute(sql2);
return Number(
res["rows"][0]["count"]
);
}
}
class NodePgTransaction extends import_pg_core.PgTransaction {
static [import_entity.entityKind] = "NodePgTransaction";
async transaction(transaction) {
const savepointName = `sp${this.nestedIndex + 1}`;
const tx = new NodePgTransaction(
this.dialect,
this.session,
this.schema,
this.nestedIndex + 1
);
await tx.execute(import_sql.sql.raw(`savepoint ${savepointName}`));
try {
const result = await transaction(tx);
await tx.execute(import_sql.sql.raw(`release savepoint ${savepointName}`));
return result;
} catch (err) {
await tx.execute(import_sql.sql.raw(`rollback to savepoint ${savepointName}`));
throw err;
}
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
NodePgPreparedQuery,
NodePgSession,
NodePgTransaction
});
//# sourceMappingURL=session.cjs.map

File diff suppressed because one or more lines are too long

48
node_modules/drizzle-orm/node-postgres/session.d.cts generated vendored Normal file
View File

@ -0,0 +1,48 @@
import type { Client, PoolClient, QueryResult, QueryResultRow } from 'pg';
import pg from 'pg';
import { entityKind } from "../entity.cjs";
import { type Logger } from "../logger.cjs";
import type { PgDialect } from "../pg-core/dialect.cjs";
import { PgTransaction } from "../pg-core/index.cjs";
import type { SelectedFieldsOrdered } from "../pg-core/query-builders/select.types.cjs";
import type { PgQueryResultHKT, PgTransactionConfig, PreparedQueryConfig } from "../pg-core/session.cjs";
import { PgPreparedQuery, PgSession } from "../pg-core/session.cjs";
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
import { type Query, type SQL } from "../sql/sql.cjs";
import { type Assume } from "../utils.cjs";
export type NodePgClient = pg.Pool | PoolClient | Client;
export declare class NodePgPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {
private client;
private params;
private logger;
private fields;
private _isResponseInArrayMode;
private customResultMapper?;
static readonly [entityKind]: string;
private rawQueryConfig;
private queryConfig;
constructor(client: NodePgClient, queryString: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, name: string | undefined, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: unknown[][]) => T["execute"]) | undefined);
execute(placeholderValues?: Record<string, unknown> | undefined): Promise<T['execute']>;
all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']>;
}
export interface NodePgSessionOptions {
logger?: Logger;
}
export declare class NodePgSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgSession<NodePgQueryResultHKT, TFullSchema, TSchema> {
private client;
private schema;
private options;
static readonly [entityKind]: string;
private logger;
constructor(client: NodePgClient, dialect: PgDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: NodePgSessionOptions);
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => T['execute']): PgPreparedQuery<T>;
transaction<T>(transaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>, config?: PgTransactionConfig | undefined): Promise<T>;
count(sql: SQL): Promise<number>;
}
export declare class NodePgTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgTransaction<NodePgQueryResultHKT, TFullSchema, TSchema> {
static readonly [entityKind]: string;
transaction<T>(transaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
}
export interface NodePgQueryResultHKT extends PgQueryResultHKT {
type: QueryResult<Assume<this['row'], QueryResultRow>>;
}

48
node_modules/drizzle-orm/node-postgres/session.d.ts generated vendored Normal file
View File

@ -0,0 +1,48 @@
import type { Client, PoolClient, QueryResult, QueryResultRow } from 'pg';
import pg from 'pg';
import { entityKind } from "../entity.js";
import { type Logger } from "../logger.js";
import type { PgDialect } from "../pg-core/dialect.js";
import { PgTransaction } from "../pg-core/index.js";
import type { SelectedFieldsOrdered } from "../pg-core/query-builders/select.types.js";
import type { PgQueryResultHKT, PgTransactionConfig, PreparedQueryConfig } from "../pg-core/session.js";
import { PgPreparedQuery, PgSession } from "../pg-core/session.js";
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
import { type Query, type SQL } from "../sql/sql.js";
import { type Assume } from "../utils.js";
export type NodePgClient = pg.Pool | PoolClient | Client;
export declare class NodePgPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {
private client;
private params;
private logger;
private fields;
private _isResponseInArrayMode;
private customResultMapper?;
static readonly [entityKind]: string;
private rawQueryConfig;
private queryConfig;
constructor(client: NodePgClient, queryString: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, name: string | undefined, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: unknown[][]) => T["execute"]) | undefined);
execute(placeholderValues?: Record<string, unknown> | undefined): Promise<T['execute']>;
all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']>;
}
export interface NodePgSessionOptions {
logger?: Logger;
}
export declare class NodePgSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgSession<NodePgQueryResultHKT, TFullSchema, TSchema> {
private client;
private schema;
private options;
static readonly [entityKind]: string;
private logger;
constructor(client: NodePgClient, dialect: PgDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: NodePgSessionOptions);
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => T['execute']): PgPreparedQuery<T>;
transaction<T>(transaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>, config?: PgTransactionConfig | undefined): Promise<T>;
count(sql: SQL): Promise<number>;
}
export declare class NodePgTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgTransaction<NodePgQueryResultHKT, TFullSchema, TSchema> {
static readonly [entityKind]: string;
transaction<T>(transaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
}
export interface NodePgQueryResultHKT extends PgQueryResultHKT {
type: QueryResult<Assume<this['row'], QueryResultRow>>;
}

187
node_modules/drizzle-orm/node-postgres/session.js generated vendored Normal file
View File

@ -0,0 +1,187 @@
import pg from "pg";
import { entityKind } from "../entity.js";
import { NoopLogger } from "../logger.js";
import { PgTransaction } from "../pg-core/index.js";
import { PgPreparedQuery, PgSession } from "../pg-core/session.js";
import { fillPlaceholders, sql } from "../sql/sql.js";
import { tracer } from "../tracing.js";
import { mapResultRow } from "../utils.js";
const { Pool, types } = pg;
class NodePgPreparedQuery extends PgPreparedQuery {
constructor(client, queryString, params, logger, fields, name, _isResponseInArrayMode, customResultMapper) {
super({ sql: queryString, params });
this.client = client;
this.params = params;
this.logger = logger;
this.fields = fields;
this._isResponseInArrayMode = _isResponseInArrayMode;
this.customResultMapper = customResultMapper;
this.rawQueryConfig = {
name,
text: queryString,
types: {
// @ts-ignore
getTypeParser: (typeId, format) => {
if (typeId === types.builtins.TIMESTAMPTZ) {
return (val) => val;
}
if (typeId === types.builtins.TIMESTAMP) {
return (val) => val;
}
if (typeId === types.builtins.DATE) {
return (val) => val;
}
if (typeId === types.builtins.INTERVAL) {
return (val) => val;
}
return types.getTypeParser(typeId, format);
}
}
};
this.queryConfig = {
name,
text: queryString,
rowMode: "array",
types: {
// @ts-ignore
getTypeParser: (typeId, format) => {
if (typeId === types.builtins.TIMESTAMPTZ) {
return (val) => val;
}
if (typeId === types.builtins.TIMESTAMP) {
return (val) => val;
}
if (typeId === types.builtins.DATE) {
return (val) => val;
}
if (typeId === types.builtins.INTERVAL) {
return (val) => val;
}
return types.getTypeParser(typeId, format);
}
}
};
}
static [entityKind] = "NodePgPreparedQuery";
rawQueryConfig;
queryConfig;
async execute(placeholderValues = {}) {
return tracer.startActiveSpan("drizzle.execute", async () => {
const params = fillPlaceholders(this.params, placeholderValues);
this.logger.logQuery(this.rawQueryConfig.text, params);
const { fields, rawQueryConfig: rawQuery, client, queryConfig: query, joinsNotNullableMap, customResultMapper } = this;
if (!fields && !customResultMapper) {
return tracer.startActiveSpan("drizzle.driver.execute", async (span) => {
span?.setAttributes({
"drizzle.query.name": rawQuery.name,
"drizzle.query.text": rawQuery.text,
"drizzle.query.params": JSON.stringify(params)
});
return client.query(rawQuery, params);
});
}
const result = await tracer.startActiveSpan("drizzle.driver.execute", (span) => {
span?.setAttributes({
"drizzle.query.name": query.name,
"drizzle.query.text": query.text,
"drizzle.query.params": JSON.stringify(params)
});
return client.query(query, params);
});
return tracer.startActiveSpan("drizzle.mapResponse", () => {
return customResultMapper ? customResultMapper(result.rows) : result.rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
});
});
}
all(placeholderValues = {}) {
return tracer.startActiveSpan("drizzle.execute", () => {
const params = fillPlaceholders(this.params, placeholderValues);
this.logger.logQuery(this.rawQueryConfig.text, params);
return tracer.startActiveSpan("drizzle.driver.execute", (span) => {
span?.setAttributes({
"drizzle.query.name": this.rawQueryConfig.name,
"drizzle.query.text": this.rawQueryConfig.text,
"drizzle.query.params": JSON.stringify(params)
});
return this.client.query(this.rawQueryConfig, params).then((result) => result.rows);
});
});
}
/** @internal */
isResponseInArrayMode() {
return this._isResponseInArrayMode;
}
}
class NodePgSession extends PgSession {
constructor(client, dialect, schema, options = {}) {
super(dialect);
this.client = client;
this.schema = schema;
this.options = options;
this.logger = options.logger ?? new NoopLogger();
}
static [entityKind] = "NodePgSession";
logger;
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper) {
return new NodePgPreparedQuery(
this.client,
query.sql,
query.params,
this.logger,
fields,
name,
isResponseInArrayMode,
customResultMapper
);
}
async transaction(transaction, config) {
const session = this.client instanceof Pool ? new NodePgSession(await this.client.connect(), this.dialect, this.schema, this.options) : this;
const tx = new NodePgTransaction(this.dialect, session, this.schema);
await tx.execute(sql`begin${config ? sql` ${tx.getTransactionConfigSQL(config)}` : void 0}`);
try {
const result = await transaction(tx);
await tx.execute(sql`commit`);
return result;
} catch (error) {
await tx.execute(sql`rollback`);
throw error;
} finally {
if (this.client instanceof Pool) {
session.client.release();
}
}
}
async count(sql2) {
const res = await this.execute(sql2);
return Number(
res["rows"][0]["count"]
);
}
}
class NodePgTransaction extends PgTransaction {
static [entityKind] = "NodePgTransaction";
async transaction(transaction) {
const savepointName = `sp${this.nestedIndex + 1}`;
const tx = new NodePgTransaction(
this.dialect,
this.session,
this.schema,
this.nestedIndex + 1
);
await tx.execute(sql.raw(`savepoint ${savepointName}`));
try {
const result = await transaction(tx);
await tx.execute(sql.raw(`release savepoint ${savepointName}`));
return result;
} catch (err) {
await tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));
throw err;
}
}
}
export {
NodePgPreparedQuery,
NodePgSession,
NodePgTransaction
};
//# sourceMappingURL=session.js.map

File diff suppressed because one or more lines are too long