-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw error when main db instance method used inside an interactive transaction #76
Comments
Hey @denis-sepirak I'm going to repurpose this issue to track adding error handling to this situation. |
Situation:@samwillis Kinda of same situation, but I'm using Nest with Drizzle ORM and reach the pglite alternative to make a E2E testing. By attempt and error, I discover that I can't use AWAIT on my client on the transaction like At the time, I could do a workaround just to satisfy my transactions on testing environment, on this case it is just one so it's fine. But if I need and want to do more transactions, it will be frustrant to set on service layer to get my NODE_ENV and do the tests, to do that I will need to inject this env globally in some state to my nest application, just to satisfy this. if (INJECTED_NODE_ENV === 'test') {
// my transaction WITHOUT await using my method from another service
// or create a new one with tx.update...
} else {
// my method from another service WITH await
} e.g.: // in my drizzle.provider.ts
const DrizzleAsyncProvider = Symbol('DrizzleAsyncProvider');
// ...
// drizzle.d.ts
export type DrizzleDB = NodePgDatabase<typeof schema>;
export type DrizzlePGLiteDB = PgliteDatabase<typeof schema>; // This one just to test my db, but it seems overhead and I'm using DrizzleDB
// my nest service
export class MyService {
constructor (
private usersService: UsersService,
private logsService: LoggersService,
private jwtService: JwtService,
@Inject(DrizzleAsyncProvider)
private db: DrizzleDB,
) {}
async signIn () {
// ...
// some validation
// transaction problem
await this.db.transaction(async () => {
// // not works
const [{ timestamp }] = await this.usersService.updateSigninTime(username);
// // works
// this.usersService.updateSigninTime(username); --> works
// // not works
await this.logsService.addLog({ username, status: 'LOGIN', historyDate: timestamp });
// // works
// this.logsService.addLog({ username, status: 'LOGIN', historyDate: timestamp });
});
// ...
}
} Packages:"@electric-sql/pglite": "^0.2.15",
"pg": "^8.13.1",
"drizzle-orm": "^0.36.4",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.0.0",
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-express": "^10.0.0", |
Is this an intended behavior? (I know that I shouldn't do this, but still)
The text was updated successfully, but these errors were encountered: