Add postgres transactions - #15
Conversation
commit: |
|
Test output. Only two new tests: Full output: |
This supports concurrent transactions as transaction ids are held as connection object state
There was a problem hiding this comment.
merge this file into config.ts, no reason these should not be co-located.
| return new RDSDataAPIDatabaseConnection({ | ||
| ...this.#config, | ||
| client: this.#client, | ||
| typeMapper: this.#config.typeMapper, | ||
| executeStatementCommand: this.#config.executeStatementCommand, | ||
| })) | ||
| }) |
There was a problem hiding this comment.
keep it flat, no need to spread everywhere.
| return new RDSDataAPIDatabaseConnection({ | |
| ...this.#config, | |
| client: this.#client, | |
| typeMapper: this.#config.typeMapper, | |
| executeStatementCommand: this.#config.executeStatementCommand, | |
| })) | |
| }) | |
| return new RDSDataAPIDatabaseConnection(this.#client, this.#config) |
| this.#config = { | ||
| client: config.client, | ||
| ...config, | ||
| typeMapper: config.typeMapper ?? new DefaultRDSDataAPITypeMapper(), | ||
| executeStatementCommand: config.executeStatementCommand, | ||
| } |
There was a problem hiding this comment.
nothing should be done here but:
this.#config: freeze({ ...config })the mapper should be instantiated on driver init.
| export type CreateBeginTransactionCommand = | ||
| () => RDSDataAPIBeginTransactionCommand | ||
|
|
||
| export type RDSDataAPIBeginTransactionCommand = object |
There was a problem hiding this comment.
I'm not sure I can enforce anything better than "A factory function that creates an object" here without direct dependency on the RDS SDK. We don't have any parameters to provide ourselves here. What would you suggest?
There was a problem hiding this comment.
something from the class' public api maybe, copied, not even precisely - just need something to hint at what this is, and fail compiling if anything but something that might be the real thing is passed.
| new RollbackTransactionCommand({ | ||
| ...connection, | ||
| ...input, | ||
| }), |
There was a problem hiding this comment.
yeah, we need to provide a helper, something like:
function createCommands(config): Pick<RDSDataAPIPostgresDialectConfig, keyof RDSDataAPIPostgresDialectConfig & `${string}Command`> {
const {
BeginTransactionCommand,
CommitTransactionCommand,
ExecuteStatementCommand,
RollbackTransactionCommand,
...connection,
} = config
return {
beginTransactionCommand: () => new BeginTransactionCommand(connection),
commitTransactionCommand: (input) => new CommitTransactionCommand({
...connection,
...input,
}),
executeStatementCommand: (input) => new ExecuteStatementCommand({
...connection,
...input,
}),
rollbackTransactionCommand: (input) => new RollbackTransactionCommand({
...connection,
...input,
}),
}
}
This tracks the active transaction id within the database connection and clears it when committed/rolled back. The RDS Data API requires that the transaction id is sent along with any successive requests within a transaction.