Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/public-kings-like.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@slonik/sql-tag": major
"slonik": major
---

Replaced `any` output types (e.g. for `sql.unknown`) with `unknown`
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2096,18 +2096,18 @@ Produces:
(template: TemplateStringsArray, ...values: ValueExpression[]) => QuerySqlToken;
```

Creates a query with Zod `any` type. The result of such a query has TypeScript type `any`.
Creates a query with Zod `unknown` type. The result of such a query has TypeScript type `unknown`.

```ts
const result = await connection.one(sql.unsafe`
SELECT foo
FROM bar
`);

// `result` type is `any`
// `result` type is `unknown`
```

`sql.unsafe` is effectively a shortcut to `sql.type(z.any())`.
`sql.unsafe` is effectively a shortcut to `sql.type(z.unknown())`.

`sql.unsafe` is as a convenience method for development. Your production code must not use `sql.unsafe`. Instead,

Expand Down
2 changes: 1 addition & 1 deletion packages/benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"pg": "^8.18.0",
"pg-promise": "^11.15.0",
"postgres": "^3.4.7",
"slonik": "^48.14.0"
"slonik": "workspace:^"
}
}
4 changes: 2 additions & 2 deletions packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"test": "ava --verbose --serial"
},
"dependencies": {
"@slonik/types": "^48.14.0",
"@slonik/utilities": "^48.14.0",
"@slonik/types": "workspace:^",
"@slonik/utilities": "workspace:^",
"roarr": "^7.21.4",
"serialize-error": "^12.0.0",
"strict-event-emitter-types": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"test": "ava --verbose --serial"
},
"dependencies": {
"@slonik/types": "^48.14.0"
"@slonik/types": "workspace:^"
},
"devDependencies": {
"@standard-schema/spec": "^1.0.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/pg-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"test": "ava --verbose --serial"
},
"dependencies": {
"@slonik/driver": "^48.14.0",
"@slonik/errors": "^48.14.0",
"@slonik/sql-tag": "^48.14.0",
"@slonik/types": "^48.14.0",
"@slonik/utilities": "^48.14.0",
"@slonik/driver": "workspace:^",
"@slonik/errors": "workspace:^",
"@slonik/sql-tag": "workspace:^",
"@slonik/types": "workspace:^",
"@slonik/utilities": "workspace:^",
"pg": "^8.18.0",
"pg-query-stream": "^4.12.0",
"pg-types": "^4.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/slonik-dataloaders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"zod": "^4.3.6"
},
"devDependencies": {
"@slonik/types": "^48.14.0",
"@slonik/types": "workspace:^",
"@standard-schema/spec": "^1.0.0",
"slonik": "^48.14.0",
"slonik": "workspace:^",
"typescript": "^5.9.3",
"vitest": "^4.0.18"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ColumnIdentifiers } from "../types";
import { createConnectionLoaderClass } from "./createConnectionLoaderClass.js";
import type { Query, QueryResultRow } from "@slonik/types";
import { parse } from "graphql";
Expand Down Expand Up @@ -584,7 +585,9 @@ describe("createConnectionLoaderClass (with validation)", () => {
const loader = new UnsafePersonConnectionLoader(pool);

const result = await loader.load({
orderBy: ({ uid }) => [[uid, "ASC"]],
orderBy: (identifiers) => [
[(identifiers as ColumnIdentifiers<{ uid: string }>).uid, "ASC"],
],
});

expect(getNodeIds(result.edges)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"devDependencies": {
"ava": "^6.4.1",
"slonik": "^48.14.0",
"slonik": "workspace:^",
"tsimp": "^2.0.12",
"typescript": "^5.9.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/slonik-interceptor-query-cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"ava": "^6.4.1",
"slonik": "^48.14.0",
"slonik": "workspace:^",
"tsimp": "^2.0.12",
"typescript": "^5.9.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/slonik-interceptor-query-logging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"ava": "^6.4.1",
"slonik": "^48.14.0",
"slonik": "workspace:^",
"tsimp": "^2.0.12",
"typescript": "^5.9.3"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/slonik-sql-tag-raw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"test": "ava --verbose --serial"
},
"dependencies": {
"@slonik/sql-tag": "^48.14.0",
"@slonik/sql-tag": "workspace:^",
"roarr": "^7.21.4"
},
"devDependencies": {
"ava": "^6.4.1",
"slonik": "^48.14.0",
"slonik": "workspace:^",
"tsimp": "^2.0.12",
"typescript": "^5.9.3"
},
Expand Down
11 changes: 6 additions & 5 deletions packages/slonik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@slonik/driver": "^48.14.0",
"@slonik/errors": "^48.14.0",
"@slonik/pg-driver": "^48.14.0",
"@slonik/sql-tag": "^48.14.0",
"@slonik/utilities": "^48.14.0",
"@slonik/driver": "workspace:^",
"@slonik/errors": "workspace:^",
"@slonik/pg-driver": "workspace:^",
"@slonik/sql-tag":"workspace:^",
"@slonik/utilities": "workspace:^",
"@standard-schema/spec": "^1.0.0",
"iso8601-duration": "^2.1.3",
"p-limit": "^6.2.0",
Expand All @@ -48,6 +48,7 @@
"zod": "^4.3.6"
},
"devDependencies": {
"@slonik/test-ssls": "workspace:^",
"@types/node": "^24.10.13",
"@types/sinon": "^20.0.0",
"ava": "^6.4.1",
Expand Down
76 changes: 59 additions & 17 deletions packages/slonik/src/helpers.test/createIntegrationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,15 @@ export const createIntegrationTests = (

const error = await t.throwsAsync(
pool.connect(async (connection) => {
const connectionPid = await connection.oneFirst(sql.unsafe`
SELECT pg_backend_pid()
`);
const connectionPid = await connection.oneFirst(
sql.type(
z.object({
pg_backend_pid: z.int(),
}),
)`
SELECT pg_backend_pid()
`,
);

setTimeout(() => {
void pool.query(sql.unsafe`SELECT pg_terminate_backend(${connectionPid})`);
Expand All @@ -602,9 +608,15 @@ export const createIntegrationTests = (

const error = await t.throwsAsync(
pool.connect(async (connection) => {
const connectionPid = await connection.oneFirst(sql.unsafe`
const connectionPid = await connection.oneFirst(
sql.type(
z.object({
pg_backend_pid: z.int(),
}),
)`
SELECT pg_backend_pid()
`);
`,
);

setTimeout(() => {
void pool.query(sql.unsafe`SELECT pg_cancel_backend(${connectionPid})`);
Expand Down Expand Up @@ -690,10 +702,16 @@ export const createIntegrationTests = (
)
`);

const result = await pool.oneFirst(sql.unsafe`
const result = await pool.oneFirst(
sql.type(
z.object({
payload: z.instanceof(Buffer),
}),
)`
SELECT payload
FROM person
`);
`,
);

t.is(result.toString(), payload);

Expand Down Expand Up @@ -766,17 +784,29 @@ export const createIntegrationTests = (
driverFactory,
});

const firstPersonId = await pool.oneFirst(sql.unsafe`
const firstPersonId = await pool.oneFirst(
sql.type(
z.object({
id: z.string(),
}),
)`
INSERT INTO person (name)
VALUES ('foo')
RETURNING id
`);
`,
);

const secondPersonId = await pool.oneFirst(sql.unsafe`
const secondPersonId = await pool.oneFirst(
sql.type(
z.object({
id: z.string(),
}),
)`
INSERT INTO person (name)
VALUES ('bar')
RETURNING id
`);
`,
);

let transactionCount = 0;

Expand Down Expand Up @@ -1269,9 +1299,15 @@ export const createIntegrationTests = (
const error = await t.throwsAsync(
pool.connect(async (connection) => {
// connection pid
const connectionPid = await connection.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
const connectionPid = await connection.oneFirst(
sql.type(
z.object({
pg_backend_pid: z.int(),
}),
)`
SELECT pg_backend_pid()
`,
);

setTimeout(() => {
void pool.query(sql.unsafe`SELECT pg_cancel_backend(${connectionPid})`);
Expand All @@ -1294,9 +1330,15 @@ export const createIntegrationTests = (
const error = await t.throwsAsync(
pool.connect(async (connection) => {
// connection pid
const connectionPid = await connection.oneFirst(sql.unsafe`
SELECT pg_backend_pid();
`);
const connectionPid = await connection.oneFirst(
sql.type(
z.object({
pg_backend_pid: z.int(),
}),
)`
SELECT pg_backend_pid()
`,
);

setTimeout(() => {
void pool.query(sql.unsafe`SELECT pg_terminate_backend(${connectionPid})`);
Expand Down
Loading