Skip to content

Sqlite nested transactions #114

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

Merged
merged 11 commits into from
Jul 29, 2025

Conversation

davecosec
Copy link
Contributor

@davecosec davecosec commented Jul 4, 2025

Added capability to use nested transactions using Savepoints. Thanks to that, we can more easily manage a typical unit of work case, where multiple transactions are handling it.

For now, it supports only SQLite, but we can also emulate that for PostgreSQL in the future.

Added also a singleton for an open transaction within a connection.

Copy link
Contributor

@oskardudycz oskardudycz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I added some suggestions around code organisation and test/ coverage. After fixing/confirming them I’ll be happy to merge it 🙂

Thanks @davecosec !

@@ -55,6 +57,8 @@ export type SQLiteClientConnectionOptions<
ConnectorType extends SQLiteConnectorType = SQLiteConnectorType,
> = {
connector: ConnectorType;
transactionCounter: TransactionNestingCounter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have transactionCounter as part of options? Shouldn’t be that created internally in the connection and kept there?🤔


const testCases = [
{ testName: 'in-memory', fileName: inMemoryfileName },
// { testName: 'file', fileName: fileName },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIX: I think that we need to test it with real file also as it has different consistency behaviour.

initTransaction: (connection) =>
sqliteTransaction(options.connector, connection),
initTransaction: (connection) => {
return sqliteTransaction(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: I think that we can simplify that by keeping transaction a singleton inside the client as SQLIte cannot have more than one open transaction. Then we could setup counter internally inside transaction without the need to pass it from the connection.

@oskardudycz
Copy link
Contributor

@davecosec I ensured that there's only one active transaction within the connection in da677ee.

That allowed the transaction nesting counter to move into the transaction.

@oskardudycz oskardudycz marked this pull request as ready for review July 29, 2025 09:37
@oskardudycz oskardudycz modified the milestones: 0.18.0, 0.17.0 Jul 29, 2025
@oskardudycz oskardudycz merged commit 2321234 into event-driven-io:main Jul 29, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants