Skip to content

Commit 2bd150e

Browse files
authored
Merge pull request #127 from 0xcadams/tx-types
fix: tx types
2 parents f23ccc2 + 103b617 commit 2bd150e

4 files changed

Lines changed: 17 additions & 19 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-zero",
3-
"version": "0.12.0",
3+
"version": "0.12.1",
44
"description": "Generate Zero schemas from Drizzle ORM schemas",
55
"type": "module",
66
"scripts": {

src/node-postgres/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import type {
77
import type { PgTransaction } from "drizzle-orm/pg-core";
88
import type { ExtractTablesWithRelations } from "drizzle-orm/relations";
99

10-
export type NodePgZeroTransaction<
11-
TDatabase extends NodePgDatabase<Record<string, unknown>>,
12-
> = Parameters<Parameters<TDatabase["transaction"]>[0]>[0] & {};
10+
export type NodePgZeroTransaction<TSchema extends Record<string, unknown>> =
11+
PgTransaction<
12+
NodePgQueryResultHKT,
13+
TSchema,
14+
ExtractTablesWithRelations<TSchema>
15+
>;
1316

1417
export class NodePgConnection<
1518
TDrizzle extends NodePgDatabase<Record<string, unknown>> & {
@@ -18,11 +21,7 @@ export class NodePgConnection<
1821
TSchema extends TDrizzle extends NodePgDatabase<infer TSchema>
1922
? TSchema
2023
: never,
21-
TTransaction extends PgTransaction<
22-
NodePgQueryResultHKT,
23-
TSchema,
24-
ExtractTablesWithRelations<TSchema>
25-
>,
24+
TTransaction extends NodePgZeroTransaction<TSchema>,
2625
> implements DBConnection<TTransaction>
2726
{
2827
readonly #drizzle: TDrizzle;

src/postgres-js/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import type {
77
import type { ExtractTablesWithRelations } from "drizzle-orm/relations";
88
import type postgres from "postgres";
99

10-
export type PostgresJsZeroTransaction<
11-
TDatabase extends PostgresJsDatabase<Record<string, unknown>>,
12-
> = Parameters<Parameters<TDatabase["transaction"]>[0]>[0] & {};
10+
export type PostgresJsZeroTransaction<TSchema extends Record<string, unknown>> =
11+
PgTransaction<
12+
PostgresJsQueryResultHKT,
13+
TSchema,
14+
ExtractTablesWithRelations<TSchema>
15+
>;
1316

1417
export class PostgresJsConnection<
1518
TDrizzle extends PostgresJsDatabase<Record<string, unknown>> & {
@@ -18,11 +21,7 @@ export class PostgresJsConnection<
1821
TSchema extends TDrizzle extends PostgresJsDatabase<infer TSchema>
1922
? TSchema
2023
: never,
21-
TTransaction extends PgTransaction<
22-
PostgresJsQueryResultHKT,
23-
TSchema,
24-
ExtractTablesWithRelations<TSchema>
25-
>,
24+
TTransaction extends PostgresJsZeroTransaction<TSchema>,
2625
> implements DBConnection<TTransaction>
2726
{
2827
readonly #drizzle: TDrizzle;

tests/pg.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("node-postgres", () => {
6363
});
6464

6565
test("types", async () => {
66-
const s = null as unknown as NodePgZeroTransaction<typeof db>;
66+
const s = null as unknown as NodePgZeroTransaction<typeof drizzleSchema>;
6767

6868
const user = null as unknown as Awaited<
6969
ReturnType<typeof s.query.user.findFirst>
@@ -210,7 +210,7 @@ describe("postgres-js", () => {
210210
});
211211

212212
test("types", async () => {
213-
const s = null as unknown as PostgresJsZeroTransaction<typeof db>;
213+
const s = null as unknown as PostgresJsZeroTransaction<typeof drizzleSchema>;
214214

215215
const user = null as unknown as Awaited<
216216
ReturnType<typeof s.query.user.findFirst>

0 commit comments

Comments
 (0)