prisma / quaint

SQL Query AST and Visitor for Rust
Apache License 2.0
582 stars 62 forks source link

fix(sqlite): do NOT create two db connections #252

Closed Weakky closed 3 years ago

Weakky commented 3 years ago

Fixes https://github.com/prisma/prisma-engines/issues/1481

This removes support for the path params "db_name". Quaint was using the ATTACH DATABASE statement as a hack to scope the db under some custom name. The ATTACH DATABASE statement is initially designed to create another connection to a different db so that one can query multiple dbs. This was causing subtle issues with transactions.

Namely, if inside a transaction, a user would "manually" execute (with executeRaw) a write without prefixing the tables with the custom db name (using one connection), and that the QE would also execute a read, this time with the tables prefixed with the db_name (therefore with another connection), this would cause two different connections attempting to do READ/WRITES inside a transaction, causing locks as explained in this doc https://sqlite.org/isolation.html

SQLite has as default db name, it's called main. This PR defaults the db_name to main. This enables:

Weakky commented 3 years ago

Great, did you test this in Prisma engines already?

When merging, remember to squash.

I did, it works. It actually works even without this fix since the QE fix no longer passes the db_name params anyway, so the attach db stuff is no longer called. PR's here, I just need to add a simple test https://github.com/prisma/prisma-engines/pull/1644