Skip to content

Commit

Permalink
Update pg and enable queryMode extended (#617)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* wip
  • Loading branch information
gajus authored Jun 5, 2024
1 parent 573616b commit 2968b32
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 49 deletions.
6 changes: 6 additions & 0 deletions .changeset/pretty-planes-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@slonik/pg-driver": minor
"slonik": minor
---

utilize extended query mode
168 changes: 122 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/pg-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"@slonik/sql-tag": "^45.5.0",
"@slonik/types": "^45.5.0",
"@slonik/utilities": "^45.5.0",
"pg-query-stream": "^4.5.5",
"pg-query-stream": "^4.6.0",
"pg-types": "^4.0.2",
"pg": "^8.11.5",
"pg": "^8.12.0",
"postgres-array": "^3.0.2"
},
"description": "A Node.js PostgreSQL client with strict types, detailed logging and assertions.",
Expand Down
2 changes: 2 additions & 0 deletions packages/pg-driver/src/factories/createPgDriverFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ const createClientConfiguration = (
options: connectionOptions.options,
password: connectionOptions.password,
port: connectionOptions.port,
// @ts-expect-error - https://github.com/brianc/node-postgres/pull/3214
queryMode: 'extended',
ssl: false,
user: connectionOptions.username,
};
Expand Down
20 changes: 19 additions & 1 deletion packages/slonik/src/helpers.test/createIntegrationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const createIntegrationTests = (
await pool.end();
});

test('produces error if multiple statements are passed as the query input', async (t) => {
test('produces error if multiple statements are passed as the query input (without parameters)', async (t) => {
const pool = await createPool(t.context.dsn, {
driverFactory,
});
Expand All @@ -153,6 +153,24 @@ export const createIntegrationTests = (
t.true(error instanceof InvalidInputError);
});

// The difference between this test and the previous one is that this one is expected to fail before the query is executed.
// In case of pg driver, that is because of the { queryMode: 'extended' } setting.
test('produces error if multiple statements are passed as the query input (with parameters)', async (t) => {
const pool = await createPool(t.context.dsn, {
driverFactory,
});

const error = await t.throwsAsync(
pool.query(sql.unsafe`
SELECT ${1}; SELECT ${2};
`),
);

// The actual error is going to be driver specific, e.g.: 'cannot insert multiple commands into a prepared statement'.
// However, Slonik will require compatible drivers to throw InputSyntaxError.
t.true(error instanceof InputSyntaxError);
});

test('NotNullIntegrityConstraintViolationError identifies the table and column', async (t) => {
const pool = await createPool(t.context.dsn, {
driverFactory,
Expand Down

0 comments on commit 2968b32

Please sign in to comment.