Replies: 5 comments 7 replies
-
|
I found that whether export type DatabaseType = typeof database;
export type TransactionType = Parameters<Parameters<DatabaseType['transaction']>[0]>[0]; |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
import type { ExtractTablesWithRelations,} from 'drizzle-orm';
import type { NodePgQueryResultHKT } from 'drizzle-orm/node-postgres';
import { PgTransaction } from 'drizzle-orm/pg-core';
import type * as schema from '@/database/schema.js';
export type Transaction = PgTransaction<NodePgQueryResultHKT, typeof schema, ExtractTablesWithRelations<typeof schema>>;You can now simply import and use |
Beta Was this translation helpful? Give feedback.
-
|
For anyone else discovering this discussion, this is how you infer the type as of the latest beta (11): import type { PgAsyncTransaction } from "drizzle-orm/pg-core";
import type { PostgresJsQueryResultHKT } from "drizzle-orm/postgres-js";
import { relations } from "./relations.ts";
export type DbTransactionType = PgAsyncTransaction<PostgresJsQueryResultHKT, Record<string, never>, typeof relations>; |
Beta Was this translation helpful? Give feedback.
-
|
This should be the way for import { SQLiteTransaction } from "drizzle-orm/sqlite-core";
import type { SqliteRemoteResult } from "drizzle-orm/sqlite-proxy";
import { relations } from "./relations.ts";
export type TransactionType = SQLiteTransaction<"async", SqliteRemoteResult, Record<string, never>, typeof relations>; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I’m using Drizzle ORM and need to pass the transaction object (
tx) to another function. Currently, I have definedtxasany, but I’d like to replace it with the correct, type-safe version.Here’s an example of my function:
Beta Was this translation helpful? Give feedback.
All reactions