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 39.1.1 to 39.2.0

2

dist/factories/createDriver.js

@@ -98,2 +98,4 @@ "use strict";

}
await query('DISCARD ALL');
// eslint-disable-next-line require-atomic-updates
isActive = false;

@@ -100,0 +102,0 @@ if (clientConfiguration.idleTimeout !== 'DISABLE_TIMEOUT') {

@@ -1194,4 +1194,123 @@ "use strict";

});
test('re-uses connections (implicit)', async (t) => {
const pool = await (0, __1.createPool)(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
const firstConnectionPid = await pool.oneFirst(__1.sql.unsafe `
SELECT pg_backend_pid();
`);
const secondConnectionPid = await pool.oneFirst(__1.sql.unsafe `
SELECT pg_backend_pid();
`);
t.is(firstConnectionPid, secondConnectionPid);
});
test('re-uses connections (explicit)', async (t) => {
const pool = await (0, __1.createPool)(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
let firstConnectionPid;
await pool.connect(async (connection) => {
firstConnectionPid = await connection.oneFirst(__1.sql.unsafe `
SELECT pg_backend_pid();
`);
});
let secondConnectionPid;
await pool.connect(async (connection) => {
secondConnectionPid = await connection.oneFirst(__1.sql.unsafe `
SELECT pg_backend_pid();
`);
});
t.is(firstConnectionPid, secondConnectionPid);
});
test('re-uses connections (transaction)', async (t) => {
const pool = await (0, __1.createPool)(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
let firstConnectionPid;
await pool.transaction(async (transaction) => {
firstConnectionPid = await transaction.oneFirst(__1.sql.unsafe `
SELECT pg_backend_pid();
`);
});
let secondConnectionPid;
await pool.transaction(async (transaction) => {
secondConnectionPid = await transaction.oneFirst(__1.sql.unsafe `
SELECT pg_backend_pid();
`);
});
t.is(firstConnectionPid, secondConnectionPid);
});
test('queues requests when the pool is full', async (t) => {
t.timeout(10000);
const pool = await (0, __1.createPool)(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
const startTime = Date.now();
await Promise.all([
await pool.query(__1.sql.unsafe `
SELECT pg_sleep(0.1)
`),
await pool.query(__1.sql.unsafe `
SELECT pg_sleep(0.1)
`),
]);
t.true(Date.now() - startTime >= 200);
});
test('does not re-use connection if there was an error', async (t) => {
const pool = await (0, __1.createPool)(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
const firstConnectionPid = await pool.oneFirst(__1.sql.unsafe `
SELECT pg_backend_pid();
`);
await t.throwsAsync(pool.query(__1.sql.unsafe `
SELECT 1 / 0;
`));
const secondConnectionPid = await pool.oneFirst(__1.sql.unsafe `
SELECT pg_backend_pid();
`);
t.not(firstConnectionPid, secondConnectionPid);
});
test('does not re-use transaction connection if there was an error', async (t) => {
const pool = await (0, __1.createPool)(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
const firstConnectionPid = await pool.oneFirst(__1.sql.unsafe `
SELECT pg_backend_pid();
`);
await t.throwsAsync(pool.transaction(async (transaction) => {
await transaction.query(__1.sql.unsafe `
SELECT 1 / 0;
`);
}));
const secondConnectionPid = await pool.oneFirst(__1.sql.unsafe `
SELECT pg_backend_pid();
`);
t.not(firstConnectionPid, secondConnectionPid);
});
test('connections are reset after they are released', async (t) => {
const pool = await (0, __1.createPool)(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
await pool.connect(async (connection) => {
await connection.query(__1.sql.unsafe `
SET slonik.foo = 'bar';
`);
t.is(await connection.oneFirst(__1.sql.unsafe `
SELECT current_setting('slonik.foo');
`), 'bar');
});
t.is(await pool.oneFirst(__1.sql.unsafe `
SELECT current_setting('slonik.foo');
`), '');
});
};
exports.createIntegrationTests = createIntegrationTests;
//# sourceMappingURL=createIntegrationTests.js.map

2

package.json

@@ -97,3 +97,3 @@ {

"types": "./dist/index.d.ts",
"version": "39.1.1"
"version": "39.2.0"
}

@@ -185,2 +185,5 @@ import { type ClientConfiguration, type TypedReadable } from '../types';

await query('DISCARD ALL');
// eslint-disable-next-line require-atomic-updates
isActive = false;

@@ -187,0 +190,0 @@

@@ -1562,2 +1562,166 @@ /* eslint-disable id-length */

});
test('re-uses connections (implicit)', async (t) => {
const pool = await createPool(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
const firstConnectionPid = await pool.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
const secondConnectionPid = await pool.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
t.is(firstConnectionPid, secondConnectionPid);
});
test('re-uses connections (explicit)', async (t) => {
const pool = await createPool(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
let firstConnectionPid: number | undefined;
await pool.connect(async (connection) => {
firstConnectionPid = await connection.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
});
let secondConnectionPid: number | undefined;
await pool.connect(async (connection) => {
secondConnectionPid = await connection.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
});
t.is(firstConnectionPid, secondConnectionPid);
});
test('re-uses connections (transaction)', async (t) => {
const pool = await createPool(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
let firstConnectionPid: number | undefined;
await pool.transaction(async (transaction) => {
firstConnectionPid = await transaction.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
});
let secondConnectionPid: number | undefined;
await pool.transaction(async (transaction) => {
secondConnectionPid = await transaction.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
});
t.is(firstConnectionPid, secondConnectionPid);
});
test('queues requests when the pool is full', async (t) => {
t.timeout(10_000);
const pool = await createPool(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
const startTime = Date.now();
await Promise.all([
await pool.query(sql.unsafe`
SELECT pg_sleep(0.1)
`),
await pool.query(sql.unsafe`
SELECT pg_sleep(0.1)
`),
]);
t.true(Date.now() - startTime >= 200);
});
test('does not re-use connection if there was an error', async (t) => {
const pool = await createPool(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
const firstConnectionPid = await pool.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
await t.throwsAsync(
pool.query(sql.unsafe`
SELECT 1 / 0;
`),
);
const secondConnectionPid = await pool.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
t.not(firstConnectionPid, secondConnectionPid);
});
test('does not re-use transaction connection if there was an error', async (t) => {
const pool = await createPool(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
const firstConnectionPid = await pool.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
await t.throwsAsync(
pool.transaction(async (transaction) => {
await transaction.query(sql.unsafe`
SELECT 1 / 0;
`);
}),
);
const secondConnectionPid = await pool.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
t.not(firstConnectionPid, secondConnectionPid);
});
test('connections are reset after they are released', async (t) => {
const pool = await createPool(t.context.dsn, {
driver,
maximumPoolSize: 1,
});
await pool.connect(async (connection) => {
await connection.query(sql.unsafe`
SET slonik.foo = 'bar';
`);
t.is(
await connection.oneFirst(sql.unsafe`
SELECT current_setting('slonik.foo');
`),
'bar',
);
});
t.is(
await pool.oneFirst(sql.unsafe`
SELECT current_setting('slonik.foo');
`),
'',
);
});
};

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

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