Immutable solution version
Usage of transactions in `:memory:` database was broken with #105
Complete solution
How to fix 'Usage of transactions in `:memory:` database was broken with #105' in Turso, straight from the verified resolution in gh:tursodatabase/libsql-client-ts#229. Root cause plus what to change.
What was reported
Issue tursodatabase/libsql-client-ts#229 (closed, 11 comments): #105 regressed in memory databases when transactions are used. Once a transaction is created, the entire in memory database will be effectively discarded for subsequent db operations that the client makes.
From the regressing PR.
1. A single connection is created lazily whenever user executes a statement 2. When a transaction starts, the Transaction object takes ownership of the current transaction. 3. Subsequent queries will create a new connection.
In particular, this [line of code](https://github.com/tursodatabase/libsql-client-ts/blob/4258668bd9659e8faaf2aba9098c20ce549bd112
The verified resolution
Honest status: STILL BROKEN on main / @libsql/client 0.17.2 per a maintainer (BartWaardenburg, CONTRIBUTOR), who re-confirmed with a 17-line repro. Root cause: PR #105 made transactions take ownership of a lazily-created connection, so on :memory: DBs the in-memory database is effectively discarded for subsequent operations after a transaction. Workaround: use file::memory:?cache=shared as the URL (shared cache mode keeps one DB; introduced ~0.8/0.9 via PR #220). Caveat: closing connections behaves oddly in shared-cache mode.
Evidence
Asked in gh:tursodatabase/libsql-client-ts#229 (https://github.com/tursodatabase/libsql-client-ts/issues/229): Usage of transactions in :memory: database was broken with #105. The issue report: Issue tursodatabase/libsql-client-ts#229 (closed, 11 comments): #105 regressed in memory databases when transactions are used. Once a transaction is created, the entire in memory database will be effectively discarded for subsequent db operations that the client makes.
From the regressing PR.
1. A single connection is created lazily whenever user executes a statement 2. When a transaction starts, the Transaction object takes ownership of the current transaction. 3. Subsequent queries will create a new connection.
In particular, this [line of code](https://github.com/tursodatabase/libsql-client-ts/blob/4258668bd9659e8faaf2aba9098c20ce549bd112 The verified answer: Honest status: STILL BROKEN on main / @libsql/client 0.17.2 per a maintainer (BartWaardenburg, CONTRIBUTOR), who re-confirmed with a 17-line repro. Root cause: PR #105 made transactions take ownership of a lazily-created connection, so on :memory: DBs the in-memory database is effectively discarded for subsequent operations after a transaction. Workaround: use file::memory:?cache=shared as the URL (shared cache mode keeps one DB; introduced ~0.8/0.9 via PR #220). Caveat: closing connections behaves oddly in shared-cache mode.
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_F9vhXJPkHsUhmwJ7-DctNQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Usage of transactions in `:memory:` database was broken with #105 <span>— Vectle</span></a>