feat: add distribution release and recovery controls
This commit is contained in:
@@ -155,6 +155,23 @@ export class DatabaseClient {
|
||||
connection.release();
|
||||
}
|
||||
}
|
||||
|
||||
async transaction<T>(operation: (database: DatabaseClient) => Promise<T>) {
|
||||
const pool = getPool();
|
||||
const connection = await pool.getConnection();
|
||||
try {
|
||||
await connection.beginTransaction();
|
||||
const transaction = new DatabaseClient(connection);
|
||||
const result = await operation(transaction);
|
||||
await connection.commit();
|
||||
return result;
|
||||
} catch (error) {
|
||||
await connection.rollback();
|
||||
throw error;
|
||||
} finally {
|
||||
connection.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
Reference in New Issue
Block a user