Socket
Socket
Sign inDemoInstall

slonik

Package Overview
Dependencies
Maintainers
1
Versions
395
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slonik - npm Package Compare versions

Comparing version 37.6.0 to 38.0.0

dist/classes/NativePostgres.d.ts

4

dist/binders/bindPool.d.ts

@@ -0,4 +1,4 @@

import { type NativePostgresPool } from '../classes/NativePostgres';
import { type ClientConfiguration, type DatabasePool, type Logger } from '../types';
import { type Pool as PgPool } from 'pg';
export declare const bindPool: (parentLog: Logger, pool: PgPool, clientConfiguration: ClientConfiguration) => DatabasePool;
export declare const bindPool: (parentLog: Logger, pool: NativePostgresPool, clientConfiguration: ClientConfiguration) => DatabasePool;
//# sourceMappingURL=bindPool.d.ts.map

@@ -0,4 +1,4 @@

import { type NativePostgresPoolClient } from '../classes/NativePostgres';
import { type ClientConfiguration, type DatabasePoolConnection, type Logger } from '../types';
import { type PoolClient as PgPoolClient } from 'pg';
export declare const bindPoolConnection: (parentLog: Logger, connection: PgPoolClient, clientConfiguration: ClientConfiguration) => DatabasePoolConnection;
export declare const bindPoolConnection: (parentLog: Logger, connection: NativePostgresPoolClient, clientConfiguration: ClientConfiguration) => DatabasePoolConnection;
//# sourceMappingURL=bindPoolConnection.d.ts.map

@@ -0,4 +1,4 @@

import { type NativePostgresPoolClient } from '../classes/NativePostgres';
import { type ClientConfiguration, type DatabaseTransactionConnection, type Logger } from '../types';
import { type PoolClient as PgPoolClient } from 'pg';
export declare const bindTransactionConnection: (parentLog: Logger, connection: PgPoolClient, clientConfiguration: ClientConfiguration, transactionDepth: number) => DatabaseTransactionConnection;
export declare const bindTransactionConnection: (parentLog: Logger, connection: NativePostgresPoolClient, clientConfiguration: ClientConfiguration, transactionDepth: number) => DatabaseTransactionConnection;
//# sourceMappingURL=bindTransactionConnection.d.ts.map

@@ -0,7 +1,7 @@

import { type NativePostgresPool, type NativePostgresPoolClient } from '../classes/NativePostgres';
import { type ClientConfiguration, type Connection, type DatabasePool, type DatabasePoolConnection, type Logger, type MaybePromise, type QuerySqlToken } from '../types';
import { type Pool as PgPool, type PoolClient as PgPoolClient } from 'pg';
type ConnectionHandlerType = (connectionLog: Logger, connection: PgPoolClient, boundConnection: DatabasePoolConnection, clientConfiguration: ClientConfiguration) => MaybePromise<unknown>;
type ConnectionHandlerType = (connectionLog: Logger, connection: NativePostgresPoolClient, boundConnection: DatabasePoolConnection, clientConfiguration: ClientConfiguration) => MaybePromise<unknown>;
type PoolHandlerType = (pool: DatabasePool) => Promise<unknown>;
export declare const createConnection: (parentLog: Logger, pool: PgPool, clientConfiguration: ClientConfiguration, connectionType: Connection, connectionHandler: ConnectionHandlerType, poolHandler: PoolHandlerType, query?: QuerySqlToken | null) => Promise<any>;
export declare const createConnection: (parentLog: Logger, pool: NativePostgresPool, clientConfiguration: ClientConfiguration, connectionType: Connection, connectionHandler: ConnectionHandlerType, poolHandler: PoolHandlerType, query?: QuerySqlToken | null) => Promise<any>;
export {};
//# sourceMappingURL=createConnection.d.ts.map

@@ -1,3 +0,3 @@

import { type Pool as PgPool, type PoolConfig } from 'pg';
export declare const createInternalPool: (Pool: new (poolConfig: PoolConfig) => PgPool, poolConfiguration: PoolConfig) => PgPool;
import { type NativePostgresPool, type NativePostgresPoolConfiguration } from '../classes/NativePostgres';
export declare const createInternalPool: (Pool: new (poolConfig: NativePostgresPoolConfiguration) => NativePostgresPool, poolConfiguration: NativePostgresPoolConfiguration) => NativePostgresPool;
//# sourceMappingURL=createInternalPool.d.ts.map

@@ -5,2 +5,3 @@ "use strict";

const bindPool_1 = require("../binders/bindPool");
const NativePostgres_1 = require("../classes/NativePostgres");
const Logger_1 = require("../Logger");

@@ -12,3 +13,2 @@ const createTypeOverrides_1 = require("../routines/createTypeOverrides");

const createPoolConfiguration_1 = require("./createPoolConfiguration");
const pg_1 = require("pg");
/**

@@ -22,3 +22,3 @@ * @param connectionUri PostgreSQL [Connection URI](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING).

if (!Pool) {
Pool = pg_1.Pool;
Pool = NativePostgres_1.NativePostgresPool;
}

@@ -25,0 +25,0 @@ if (!Pool) {

@@ -0,4 +1,4 @@

import { type NativePostgresPoolConfiguration } from '../classes/NativePostgres';
import { type ClientConfiguration } from '../types';
import { type PoolConfig } from 'pg';
export declare const createPoolConfiguration: (dsn: string, clientConfiguration: ClientConfiguration) => PoolConfig;
export declare const createPoolConfiguration: (dsn: string, clientConfiguration: ClientConfiguration) => NativePostgresPoolConfiguration;
//# sourceMappingURL=createPoolConfiguration.d.ts.map

@@ -76,2 +76,59 @@ "use strict";

});
/**
* https://github.com/gajus/slonik/pull/552
*/
test('copes with dollar-number in table name', (t) => {
const query0 = sql.fragment `discounted_to_$1 (offer_id INTEGER)`;
const query1 = sql.fragment `CREATE TABLE ${query0}`;
t.deepEqual(query1, {
sql: 'CREATE TABLE discounted_to_$1 (offer_id INTEGER)',
type: tokens_1.FragmentToken,
values: [],
});
});
/**
* https://github.com/gajus/slonik/pull/552
*/
test('copes with dollar-number in column name (CREATE TABLE)', (t) => {
const query0 = sql.fragment `offers (discounted_to_$1 BOOLEAN)`;
const query1 = sql.fragment `CREATE TABLE ${query0}`;
t.deepEqual(query1, {
sql: 'CREATE TABLE offers (discounted_to_$1 BOOLEAN)',
type: tokens_1.FragmentToken,
values: [],
});
});
/**
* https://github.com/gajus/slonik/pull/552
*/
test('copes with dollar-number in column name (SELECT)', (t) => {
const query0 = sql.fragment `"discounted_to_$1" IS TRUE`;
const query1 = sql.fragment `SELECT * FROM offers WHERE ${query0}`;
t.deepEqual(query1, {
sql: 'SELECT * FROM offers WHERE "discounted_to_$1" IS TRUE',
type: tokens_1.FragmentToken,
values: [],
});
});
/**
* https://github.com/gajus/slonik/pull/552
*/
test('copes with dollar-number in function definitions', (t) => {
// example function from https://www.postgresql.org/docs/current/sql-createfunction.html
const query0 = sql.fragment `add(integer, integer) RETURNS integer
AS 'select $1 + $2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT`;
const query1 = sql.fragment `CREATE FUNCTION ${query0}`;
t.deepEqual(query1, {
sql: `CREATE FUNCTION add(integer, integer) RETURNS integer
AS 'select $1 + $2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT`,
type: tokens_1.FragmentToken,
values: [],
});
});
//# sourceMappingURL=sql.test.js.map

@@ -0,3 +1,3 @@

import { type NativePostgresPool, type NativePostgresPoolConfiguration } from '../classes/NativePostgres';
import { type TestFn } from 'ava';
import { type Pool as PgPoolType, type PoolConfig } from 'pg';
type TestContextType = {

@@ -7,7 +7,7 @@ dsn: string;

};
export declare const createTestRunner: (PgPool: new (poolConfig: PoolConfig) => PgPoolType, name: string) => {
export declare const createTestRunner: (PgPool: new (poolConfig: NativePostgresPoolConfiguration) => NativePostgresPool, name: string) => {
test: TestFn<TestContextType>;
};
export declare const createIntegrationTests: (test: TestFn<TestContextType>, PgPool: new () => PgPoolType) => void;
export declare const createIntegrationTests: (test: TestFn<TestContextType>, PgPool: new () => NativePostgresPool) => void;
export {};
//# sourceMappingURL=createIntegrationTests.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
const NativePostgres_1 = require("../classes/NativePostgres");
const createIntegrationTests_1 = require("../helpers/createIntegrationTests");
const pg_1 = require("pg");
const { test } = (0, createIntegrationTests_1.createTestRunner)(pg_1.Pool, 'pg');
(0, createIntegrationTests_1.createIntegrationTests)(test, pg_1.Pool);
const { test } = (0, createIntegrationTests_1.createTestRunner)(NativePostgres_1.NativePostgresPool, 'pg');
(0, createIntegrationTests_1.createIntegrationTests)(test, NativePostgres_1.NativePostgresPool);
test('returns expected query result object (NOTICE)', async (t) => {
const pool = await (0, __1.createPool)(t.context.dsn, {
PgPool: pg_1.Pool,
PgPool: NativePostgres_1.NativePostgresPool,
});

@@ -12,0 +12,0 @@ await pool.query(__1.sql.unsafe `

@@ -6,4 +6,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const NativePostgres_1 = require("../classes/NativePostgres");
const createIntegrationTests_1 = require("../helpers/createIntegrationTests");
const pg_1 = require("pg");
const postgres_1 = __importDefault(require("postgres"));

@@ -13,3 +13,3 @@ const postgres_bridge_1 = require("postgres-bridge");

const { test } = (0, createIntegrationTests_1.createTestRunner)(Pool, 'postgres-bridge');
(0, createIntegrationTests_1.createIntegrationTests)(test, pg_1.Pool);
(0, createIntegrationTests_1.createIntegrationTests)(test, NativePostgres_1.NativePostgresPool);
//# sourceMappingURL=postgres.test.js.map

@@ -27,7 +27,7 @@ "use strict";

const __1 = require("..");
const NativePostgres_1 = require("../classes/NativePostgres");
const createIntegrationTests_1 = require("../helpers/createIntegrationTests");
const pg_1 = require("pg");
const sinon = __importStar(require("sinon"));
const zod_1 = require("zod");
const { test } = (0, createIntegrationTests_1.createTestRunner)(pg_1.Pool, 'pg');
const { test } = (0, createIntegrationTests_1.createTestRunner)(NativePostgres_1.NativePostgresPool, 'pg');
test('reading stream after a delay', async (t) => {

@@ -34,0 +34,0 @@ const pool = await (0, __1.createPool)(t.context.dsn, {

@@ -0,4 +1,4 @@

import { type NativePostgresPoolClient } from '../classes/NativePostgres';
import { type TypeParser } from '../types';
import { type PoolClient } from 'pg';
export declare const createTypeOverrides: (connection: PoolClient, typeParsers: readonly TypeParser[]) => Promise<(oid: number) => any>;
export declare const createTypeOverrides: (connection: NativePostgresPoolClient, typeParsers: readonly TypeParser[]) => Promise<(oid: number) => any>;
//# sourceMappingURL=createTypeOverrides.d.ts.map

@@ -0,4 +1,4 @@

import { type NativePostgresPool, type NativePostgresPoolClient } from '../classes/NativePostgres';
import { type Logger } from '../types';
import { type Pool as PgPool, type PoolClient as PgPoolClient } from 'pg';
export declare const establishConnection: (parentLog: Logger, pool: PgPool, connectionRetryLimit: number) => Promise<PgPoolClient>;
export declare const establishConnection: (parentLog: Logger, pool: NativePostgresPool, connectionRetryLimit: number) => Promise<NativePostgresPoolClient>;
//# sourceMappingURL=establishConnection.d.ts.map

@@ -0,7 +1,7 @@

import { type NativePostgresPoolClient } from '../classes/NativePostgres';
import { type ClientConfiguration, type Logger, type PrimitiveValueExpression, type Query, type QueryContext, type QueryId, type QueryResult, type QueryResultRow, type QuerySqlToken, type StreamResult } from '../types';
import { type PoolClient as PgPoolClient } from 'pg';
type GenericQueryResult = StreamResult | QueryResult<QueryResultRow>;
export type ExecutionRoutine = (connection: PgPoolClient, sql: string, values: readonly PrimitiveValueExpression[], queryContext: QueryContext, query: Query) => Promise<GenericQueryResult>;
export declare const executeQuery: (connectionLogger: Logger, connection: PgPoolClient, clientConfiguration: ClientConfiguration, query: QuerySqlToken, inheritedQueryId: QueryId | undefined, executionRoutine: ExecutionRoutine, stream: boolean) => Promise<StreamResult | QueryResult<Record<string, PrimitiveValueExpression>>>;
export type ExecutionRoutine = (connection: NativePostgresPoolClient, sql: string, values: readonly PrimitiveValueExpression[], queryContext: QueryContext, query: Query) => Promise<GenericQueryResult>;
export declare const executeQuery: (connectionLogger: Logger, connection: NativePostgresPoolClient, clientConfiguration: ClientConfiguration, query: QuerySqlToken, inheritedQueryId: QueryId | undefined, executionRoutine: ExecutionRoutine, stream: boolean) => Promise<StreamResult | QueryResult<Record<string, PrimitiveValueExpression>>>;
export {};
//# sourceMappingURL=executeQuery.d.ts.map

@@ -0,4 +1,4 @@

import { type NativePostgresPool, type NativePostgresPoolClient } from './classes/NativePostgres';
import { type TypeOverrides } from './types';
import { type DeferredPromise } from './utilities/defer';
import { type Pool as PgPool, type PoolClient as PgClientPool } from 'pg';
export type PoolState = {

@@ -19,7 +19,7 @@ ended: boolean;

};
export declare const poolStateMap: WeakMap<PgPool, PoolState>;
export declare const poolClientStateMap: WeakMap<PgClientPool, PoolClientState>;
export declare const getPoolState: (pool: PgPool) => PoolState;
export declare const getPoolClientState: (poolClient: PgClientPool) => PoolClientState;
export declare const poolStateMap: WeakMap<NativePostgresPool, PoolState>;
export declare const poolClientStateMap: WeakMap<NativePostgresPoolClient, PoolClientState>;
export declare const getPoolState: (pool: NativePostgresPool) => PoolState;
export declare const getPoolClientState: (poolClient: NativePostgresPoolClient) => PoolClientState;
export {};
//# sourceMappingURL=state.d.ts.map
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { type NativePostgresPool, type NativePostgresPoolClient, type NativePostgresPoolConfiguration } from './classes/NativePostgres';
import { type SlonikError } from './errors';

@@ -8,3 +9,2 @@ import type * as tokens from './tokens';

import { type ConnectionOptions as TlsConnectionOptions } from 'node:tls';
import { type Pool as PgPool, type PoolClient as PgPoolClient, type PoolConfig } from 'pg';
import { type NoticeMessage as Notice } from 'pg-protocol/dist/messages';

@@ -63,3 +63,3 @@ import { type Logger } from 'roarr';

*/
readonly PgPool?: new (poolConfig: PoolConfig) => PgPool;
readonly PgPool?: new (poolConfig: NativePostgresPoolConfiguration) => NativePostgresPool;
/**

@@ -308,6 +308,6 @@ * Dictates whether to capture stack trace before executing query. Middlewares access stack trace through query execution context. (Default: true)

};
export type InternalQueryMethod<R = any> = (log: Logger, connection: PgPoolClient, clientConfiguration: ClientConfiguration, slonikSql: QuerySqlToken, uid?: QueryId) => R;
export type InternalStreamFunction = <T>(log: Logger, connection: PgPoolClient, clientConfiguration: ClientConfiguration, slonikSql: QuerySqlToken, streamHandler: StreamHandler<T>, uid?: QueryId, config?: QueryStreamConfig) => Promise<StreamResult>;
export type InternalTransactionFunction = <T>(log: Logger, connection: PgPoolClient, clientConfiguration: ClientConfiguration, handler: TransactionFunction<T>, transactionRetryLimit?: number) => Promise<T>;
export type InternalNestedTransactionFunction = <T>(log: Logger, connection: PgPoolClient, clientConfiguration: ClientConfiguration, handler: TransactionFunction<T>, transactionDepth: number, transactionRetryLimit?: number) => Promise<T>;
export type InternalQueryMethod<R = any> = (log: Logger, connection: NativePostgresPoolClient, clientConfiguration: ClientConfiguration, slonikSql: QuerySqlToken, uid?: QueryId) => R;
export type InternalStreamFunction = <T>(log: Logger, connection: NativePostgresPoolClient, clientConfiguration: ClientConfiguration, slonikSql: QuerySqlToken, streamHandler: StreamHandler<T>, uid?: QueryId, config?: QueryStreamConfig) => Promise<StreamResult>;
export type InternalTransactionFunction = <T>(log: Logger, connection: NativePostgresPoolClient, clientConfiguration: ClientConfiguration, handler: TransactionFunction<T>, transactionRetryLimit?: number) => Promise<T>;
export type InternalNestedTransactionFunction = <T>(log: Logger, connection: NativePostgresPoolClient, clientConfiguration: ClientConfiguration, handler: TransactionFunction<T>, transactionDepth: number, transactionRetryLimit?: number) => Promise<T>;
type QueryAnyFirstFunction = <T extends ZodTypeAny>(sql: QuerySqlToken<T>, values?: PrimitiveValueExpression[]) => Promise<ReadonlyArray<z.infer<T>[keyof z.infer<T>]>>;

@@ -314,0 +314,0 @@ type QueryAnyFunction = <T extends ZodTypeAny>(sql: QuerySqlToken<T>, values?: PrimitiveValueExpression[]) => Promise<ReadonlyArray<z.infer<T>>>;

@@ -38,3 +38,2 @@ {

"nyc": "^15.1.0",
"pg-native": "^3.0.1",
"postgres": "^3.4.4",

@@ -101,3 +100,3 @@ "postgres-bridge": "^1.14.0",

"types": "./dist/index.d.ts",
"version": "37.6.0"
"version": "38.0.0"
}

@@ -0,1 +1,2 @@

import { type NativePostgresPool } from '../classes/NativePostgres';
import { transaction } from '../connectionMethods/transaction';

@@ -9,7 +10,6 @@ import { createConnection } from '../factories/createConnection';

} from '../types';
import { type Pool as PgPool } from 'pg';
export const bindPool = (
parentLog: Logger,
pool: PgPool,
pool: NativePostgresPool,
clientConfiguration: ClientConfiguration,

@@ -16,0 +16,0 @@ ): DatabasePool => {

@@ -0,1 +1,2 @@

import { type NativePostgresPoolClient } from '../classes/NativePostgres';
import { any } from '../connectionMethods/any';

@@ -18,7 +19,6 @@ import { anyFirst } from '../connectionMethods/anyFirst';

} from '../types';
import { type PoolClient as PgPoolClient } from 'pg';
export const bindPoolConnection = (
parentLog: Logger,
connection: PgPoolClient,
connection: NativePostgresPoolClient,
clientConfiguration: ClientConfiguration,

@@ -25,0 +25,0 @@ ): DatabasePoolConnection => {

@@ -0,1 +1,2 @@

import { type NativePostgresPoolClient } from '../classes/NativePostgres';
import { any } from '../connectionMethods/any';

@@ -19,7 +20,6 @@ import { anyFirst } from '../connectionMethods/anyFirst';

} from '../types';
import { type PoolClient as PgPoolClient } from 'pg';
export const bindTransactionConnection = (
parentLog: Logger,
connection: PgPoolClient,
connection: NativePostgresPoolClient,
clientConfiguration: ClientConfiguration,

@@ -26,0 +26,0 @@ transactionDepth: number,

@@ -0,1 +1,2 @@

import { type NativePostgresQueryResult } from '../classes/NativePostgres';
import { executeQuery, type ExecutionRoutine } from '../routines/executeQuery';

@@ -8,3 +9,2 @@ import {

} from '../types';
import { type QueryResult as PgQueryResult } from 'pg';

@@ -16,3 +16,3 @@ const executionRoutine: ExecutionRoutine = async (

) => {
const result: PgQueryResult & { notices?: Notice[] } =
const result: NativePostgresQueryResult & { notices?: Notice[] } =
await finalConnection.query(

@@ -19,0 +19,0 @@ finalSql,

@@ -0,1 +1,2 @@

import { type NativePostgresPoolClient } from '../classes/NativePostgres';
import { executeQuery, type ExecutionRoutine } from '../routines/executeQuery';

@@ -14,3 +15,2 @@ import {

import { pipeline } from 'node:stream/promises';
import { type PoolClient } from 'pg';
import QueryStream from 'pg-query-stream';

@@ -21,3 +21,3 @@

const createTransformStream = (
connection: PoolClient,
connection: NativePostgresPoolClient,
clientConfiguration: ClientConfiguration,

@@ -24,0 +24,0 @@ queryContext: QueryContext,

import { bindPoolConnection } from '../binders/bindPoolConnection';
import {
type NativePostgresPool,
type NativePostgresPoolClient,
} from '../classes/NativePostgres';
import { UnexpectedStateError } from '../errors';

@@ -14,7 +18,6 @@ import { establishConnection } from '../routines/establishConnection';

} from '../types';
import { type Pool as PgPool, type PoolClient as PgPoolClient } from 'pg';
type ConnectionHandlerType = (
connectionLog: Logger,
connection: PgPoolClient,
connection: NativePostgresPoolClient,
boundConnection: DatabasePoolConnection,

@@ -26,3 +29,3 @@ clientConfiguration: ClientConfiguration,

const terminatePoolConnection = (connection: PgPoolClient) => {
const terminatePoolConnection = (connection: NativePostgresPoolClient) => {
// tells the pool to destroy this client

@@ -57,3 +60,3 @@ connection.release(true);

parentLog: Logger,
pool: PgPool,
pool: NativePostgresPool,
clientConfiguration: ClientConfiguration,

@@ -60,0 +63,0 @@ connectionType: Connection,

@@ -0,10 +1,13 @@

import {
type NativePostgresPool,
type NativePostgresPoolConfiguration,
} from '../classes/NativePostgres';
import { Logger } from '../Logger';
import { poolStateMap } from '../state';
import { createUid } from '../utilities/createUid';
import { type Pool as PgPool, type PoolConfig } from 'pg';
import { serializeError } from 'serialize-error';
export const createInternalPool = (
Pool: new (poolConfig: PoolConfig) => PgPool,
poolConfiguration: PoolConfig,
Pool: new (poolConfig: NativePostgresPoolConfiguration) => NativePostgresPool,
poolConfiguration: NativePostgresPoolConfiguration,
) => {

@@ -17,3 +20,3 @@ const poolId = createUid();

const pool: PgPool = new Pool({
const pool: NativePostgresPool = new Pool({
...poolConfiguration,

@@ -20,0 +23,0 @@ });

import { bindPool } from '../binders/bindPool';
import {
type NativePostgresPool,
type NativePostgresPoolClient,
} from '../classes/NativePostgres';
import { Logger } from '../Logger';

@@ -11,3 +15,2 @@ import { poolStateMap } from '../state';

import { createClientConfiguration } from './createClientConfiguration';
import { type Pool as PgPool, type PoolClient as PgClientPool } from 'pg';

@@ -35,3 +38,3 @@ export const createMockPool = (

release: () => {},
} as unknown as PgClientPool;
} as unknown as NativePostgresPoolClient;

@@ -41,3 +44,3 @@ return connection;

end: async () => {},
} as unknown as PgPool;
} as unknown as NativePostgresPool;

@@ -44,0 +47,0 @@ poolStateMap.set(pool, {

import { bindPool } from '../binders/bindPool';
import { NativePostgresPool } from '../classes/NativePostgres';
import { Logger } from '../Logger';

@@ -9,3 +10,2 @@ import { createTypeOverrides } from '../routines/createTypeOverrides';

import { createPoolConfiguration } from './createPoolConfiguration';
import { Pool as PgPool } from 'pg';
import type pgTypes from 'pg-types';

@@ -32,3 +32,3 @@

if (!Pool) {
Pool = PgPool;
Pool = NativePostgresPool;
}

@@ -35,0 +35,0 @@

/* eslint-disable canonical/id-match */
import { type NativePostgresPoolConfiguration } from '../classes/NativePostgres';
import { Logger as log } from '../Logger';
import { type ClientConfiguration } from '../types';
import { parseDsn } from '../utilities/parseDsn';
import { type PoolConfig } from 'pg';

@@ -11,6 +11,6 @@ export const createPoolConfiguration = (

clientConfiguration: ClientConfiguration,
): PoolConfig => {
): NativePostgresPoolConfiguration => {
const connectionOptions = parseDsn(dsn);
const poolConfiguration: PoolConfig = {
const poolConfiguration: NativePostgresPoolConfiguration = {
application_name: connectionOptions.applicationName,

@@ -17,0 +17,0 @@ database: connectionOptions.databaseName,

@@ -96,1 +96,66 @@ import { FragmentToken } from '../../tokens';

});
/**
* https://github.com/gajus/slonik/pull/552
*/
test('copes with dollar-number in table name', (t) => {
const query0 = sql.fragment`discounted_to_$1 (offer_id INTEGER)`;
const query1 = sql.fragment`CREATE TABLE ${query0}`;
t.deepEqual(query1, {
sql: 'CREATE TABLE discounted_to_$1 (offer_id INTEGER)',
type: FragmentToken,
values: [],
});
});
/**
* https://github.com/gajus/slonik/pull/552
*/
test('copes with dollar-number in column name (CREATE TABLE)', (t) => {
const query0 = sql.fragment`offers (discounted_to_$1 BOOLEAN)`;
const query1 = sql.fragment`CREATE TABLE ${query0}`;
t.deepEqual(query1, {
sql: 'CREATE TABLE offers (discounted_to_$1 BOOLEAN)',
type: FragmentToken,
values: [],
});
});
/**
* https://github.com/gajus/slonik/pull/552
*/
test('copes with dollar-number in column name (SELECT)', (t) => {
const query0 = sql.fragment`"discounted_to_$1" IS TRUE`;
const query1 = sql.fragment`SELECT * FROM offers WHERE ${query0}`;
t.deepEqual(query1, {
sql: 'SELECT * FROM offers WHERE "discounted_to_$1" IS TRUE',
type: FragmentToken,
values: [],
});
});
/**
* https://github.com/gajus/slonik/pull/552
*/
test('copes with dollar-number in function definitions', (t) => {
// example function from https://www.postgresql.org/docs/current/sql-createfunction.html
const query0 = sql.fragment`add(integer, integer) RETURNS integer
AS 'select $1 + $2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT`;
const query1 = sql.fragment`CREATE FUNCTION ${query0}`;
t.deepEqual(query1, {
sql: `CREATE FUNCTION add(integer, integer) RETURNS integer
AS 'select $1 + $2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT`,
type: FragmentToken,
values: [],
});
});

@@ -17,6 +17,9 @@ /* eslint-disable id-length */

} from '..';
import {
type NativePostgresPool,
type NativePostgresPoolConfiguration,
} from '../classes/NativePostgres';
import { Logger } from '../Logger';
import anyTest, { type TestFn } from 'ava';
import { setTimeout as delay } from 'node:timers/promises';
import { type Pool as PgPoolType, type PoolConfig } from 'pg';
import { serializeError } from 'serialize-error';

@@ -39,3 +42,5 @@ import * as sinon from 'sinon';

export const createTestRunner = (
PgPool: new (poolConfig: PoolConfig) => PgPoolType,
PgPool: new (
poolConfig: NativePostgresPoolConfiguration,
) => NativePostgresPool,
name: string,

@@ -147,3 +152,3 @@ ) => {

test: TestFn<TestContextType>,
PgPool: new () => PgPoolType,
PgPool: new () => NativePostgresPool,
) => {

@@ -150,0 +155,0 @@ test('inserts and retrieves bigint', async (t) => {

import { createPool, sql } from '..';
import { NativePostgresPool } from '../classes/NativePostgres';
import {

@@ -6,11 +7,10 @@ createIntegrationTests,

} from '../helpers/createIntegrationTests';
import { Pool as PgPool } from 'pg';
const { test } = createTestRunner(PgPool, 'pg');
const { test } = createTestRunner(NativePostgresPool, 'pg');
createIntegrationTests(test, PgPool);
createIntegrationTests(test, NativePostgresPool);
test('returns expected query result object (NOTICE)', async (t) => {
const pool = await createPool(t.context.dsn, {
PgPool,
PgPool: NativePostgresPool,
});

@@ -17,0 +17,0 @@

@@ -0,1 +1,2 @@

import { NativePostgresPool } from '../classes/NativePostgres';
import {

@@ -5,10 +6,11 @@ createIntegrationTests,

} from '../helpers/createIntegrationTests';
import { Pool as PgPool } from 'pg';
import postgres from 'postgres';
import { createPostgresBridge } from 'postgres-bridge';
const Pool = createPostgresBridge(postgres) as unknown as typeof PgPool;
const Pool = createPostgresBridge(
postgres,
) as unknown as typeof NativePostgresPool;
const { test } = createTestRunner(Pool, 'postgres-bridge');
createIntegrationTests(test, PgPool);
createIntegrationTests(test, NativePostgresPool);

@@ -7,8 +7,8 @@ import {

} from '..';
import { NativePostgresPool } from '../classes/NativePostgres';
import { createTestRunner } from '../helpers/createIntegrationTests';
import { Pool as PgPool } from 'pg';
import * as sinon from 'sinon';
import { z } from 'zod';
const { test } = createTestRunner(PgPool, 'pg');
const { test } = createTestRunner(NativePostgresPool, 'pg');

@@ -15,0 +15,0 @@ test('reading stream after a delay', async (t) => {

@@ -0,3 +1,3 @@

import { type NativePostgresPoolClient } from '../classes/NativePostgres';
import { type TypeParser } from '../types';
import { type PoolClient } from 'pg';
import { getTypeParser } from 'pg-types';

@@ -13,3 +13,3 @@ import { parse as parseArray } from 'postgres-array';

export const createTypeOverrides = async (
connection: PoolClient,
connection: NativePostgresPoolClient,
typeParsers: readonly TypeParser[],

@@ -16,0 +16,0 @@ ) => {

@@ -0,1 +1,2 @@

import { type NativePostgresPool } from '../classes/NativePostgres';
import { Logger } from '../Logger';

@@ -5,3 +6,2 @@ import { type PoolState, poolStateMap } from '../state';

import test from 'ava';
import { type Pool as PgPool } from 'pg';
import * as sinon from 'sinon';

@@ -14,3 +14,6 @@

poolStateMap.set(pool as unknown as PgPool, {} as unknown as PoolState);
poolStateMap.set(
pool as unknown as NativePostgresPool,
{} as unknown as PoolState,
);

@@ -22,3 +25,3 @@ const connectionRetryLimit = 3;

Logger,
pool as unknown as PgPool,
pool as unknown as NativePostgresPool,
connectionRetryLimit,

@@ -36,3 +39,6 @@ ),

poolStateMap.set(pool as unknown as PgPool, {} as unknown as PoolState);
poolStateMap.set(
pool as unknown as NativePostgresPool,
{} as unknown as PoolState,
);

@@ -44,3 +50,3 @@ const connectionRetryLimit = 0;

Logger,
pool as unknown as PgPool,
pool as unknown as NativePostgresPool,
connectionRetryLimit,

@@ -47,0 +53,0 @@ ),

@@ -0,1 +1,5 @@

import {
type NativePostgresPool,
type NativePostgresPoolClient,
} from '../classes/NativePostgres';
import { ConnectionError, UnexpectedStateError } from '../errors';

@@ -5,3 +9,2 @@ import { getPoolState, poolClientStateMap } from '../state';

import { createUid } from '../utilities/createUid';
import { type Pool as PgPool, type PoolClient as PgPoolClient } from 'pg';
import { serializeError } from 'serialize-error';

@@ -11,3 +14,3 @@

parentLog: Logger,
pool: PgPool,
pool: NativePostgresPool,
connectionRetryLimit: number,

@@ -17,3 +20,3 @@ ) => {

let connection: PgPoolClient;
let connection: NativePostgresPoolClient;

@@ -20,0 +23,0 @@ let remainingConnectionRetryLimit = connectionRetryLimit + 1;

@@ -0,1 +1,2 @@

import { type NativePostgresPoolClient } from '../classes/NativePostgres';
import { TRANSACTION_ROLLBACK_ERROR_PREFIX } from '../constants';

@@ -34,3 +35,2 @@ import {

import { getStackTrace } from 'get-stack-trace';
import { type PoolClient as PgPoolClient } from 'pg';
import { serializeError } from 'serialize-error';

@@ -41,3 +41,3 @@

export type ExecutionRoutine = (
connection: PgPoolClient,
connection: NativePostgresPoolClient,
sql: string,

@@ -58,3 +58,3 @@ values: readonly PrimitiveValueExpression[],

connectionLogger: Logger,
connection: PgPoolClient,
connection: NativePostgresPoolClient,
query: TransactionQuery,

@@ -125,3 +125,3 @@ retryLimit: number,

connectionLogger: Logger,
connection: PgPoolClient,
connection: NativePostgresPoolClient,
clientConfiguration: ClientConfiguration,

@@ -128,0 +128,0 @@ query: QuerySqlToken,

@@ -0,5 +1,8 @@

import {
type NativePostgresPool,
type NativePostgresPoolClient,
} from './classes/NativePostgres';
import { UnexpectedStateError } from './errors';
import { type TypeOverrides } from './types';
import { type DeferredPromise } from './utilities/defer';
import { type Pool as PgPool, type PoolClient as PgClientPool } from 'pg';

@@ -23,7 +26,10 @@ export type PoolState = {

export const poolStateMap = new WeakMap<PgPool, PoolState>();
export const poolStateMap = new WeakMap<NativePostgresPool, PoolState>();
export const poolClientStateMap = new WeakMap<PgClientPool, PoolClientState>();
export const poolClientStateMap = new WeakMap<
NativePostgresPoolClient,
PoolClientState
>();
export const getPoolState = (pool: PgPool): PoolState => {
export const getPoolState = (pool: NativePostgresPool): PoolState => {
const poolState = poolStateMap.get(pool);

@@ -39,3 +45,3 @@

export const getPoolClientState = (
poolClient: PgClientPool,
poolClient: NativePostgresPoolClient,
): PoolClientState => {

@@ -42,0 +48,0 @@ const poolClientState = poolClientStateMap.get(poolClient);

@@ -0,1 +1,6 @@

import {
type NativePostgresPool,
type NativePostgresPoolClient,
type NativePostgresPoolConfiguration,
} from './classes/NativePostgres';
import { type SlonikError } from './errors';

@@ -5,7 +10,2 @@ import type * as tokens from './tokens';

import { type ConnectionOptions as TlsConnectionOptions } from 'node:tls';
import {
type Pool as PgPool,
type PoolClient as PgPoolClient,
type PoolConfig,
} from 'pg';
import { type NoticeMessage as Notice } from 'pg-protocol/dist/messages';

@@ -97,3 +97,5 @@ import { type Logger } from 'roarr';

*/
readonly PgPool?: new (poolConfig: PoolConfig) => PgPool;
readonly PgPool?: new (
poolConfig: NativePostgresPoolConfiguration,
) => NativePostgresPool;
/**

@@ -445,3 +447,3 @@ * Dictates whether to capture stack trace before executing query. Middlewares access stack trace through query execution context. (Default: true)

log: Logger,
connection: PgPoolClient,
connection: NativePostgresPoolClient,
clientConfiguration: ClientConfiguration,

@@ -454,3 +456,3 @@ slonikSql: QuerySqlToken,

log: Logger,
connection: PgPoolClient,
connection: NativePostgresPoolClient,
clientConfiguration: ClientConfiguration,

@@ -465,3 +467,3 @@ slonikSql: QuerySqlToken,

log: Logger,
connection: PgPoolClient,
connection: NativePostgresPoolClient,
clientConfiguration: ClientConfiguration,

@@ -474,3 +476,3 @@ handler: TransactionFunction<T>,

log: Logger,
connection: PgPoolClient,
connection: NativePostgresPoolClient,
clientConfiguration: ClientConfiguration,

@@ -477,0 +479,0 @@ handler: TransactionFunction<T>,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc