Replies: 5 comments 7 replies
|
I found that whether export type DatabaseType = typeof database;
export type TransactionType = Parameters<Parameters<DatabaseType['transaction']>[0]>[0]; |
3 replies
2 replies
|
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 |
1 reply
|
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>; |
0 replies
|
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>; |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
All reactions