Bea dm
Bea dm
DTDrizzle Team
Created by CODY on 12/23/2023 in #help
Can I .prepare() a transaction?
Hi, is there any documentation about this? i just only found this https://github.com/ItzDerock/hostforge/blob/9798ab27fc7a1b960f7c94be46b3f3310c8cfc72/src/server/api/routers/projects/service/index.ts#L81C50-L81C72 but not sure, in my code session does not exist if i type it. I tried this with no luck could you help me a bit please?
const insertScoreCard = (db: DatabaseClient) => db.insert(scoreCards).values({ .. }).prepare('insert_score_card');
export const createScorecard = (dbClient: DatabaseClient) => async () => {
await dbClient.transaction(async (trx: PostgresTransaction) => {
const db: DatabaseClient = trx.session.client;
// Prepare the statements for scorecards
const insertStatement = insertScoreCard(db);
const insertedScoreCard = await insertStatement.run(newScoreCard);
...
};
const insertScoreCard = (db: DatabaseClient) => db.insert(scoreCards).values({ .. }).prepare('insert_score_card');
export const createScorecard = (dbClient: DatabaseClient) => async () => {
await dbClient.transaction(async (trx: PostgresTransaction) => {
const db: DatabaseClient = trx.session.client;
// Prepare the statements for scorecards
const insertStatement = insertScoreCard(db);
const insertedScoreCard = await insertStatement.run(newScoreCard);
...
};
5 replies