Is it possible to use D1 to get a read transaction?
The only “transaction” API I can see is db.batch (doc)
But the issue with this is that it just writes multiple statements. I want to get a “read transaction” where I can read data from a snapshot, and then optionally perform writes, then read from the current transaction again.
SQLite supports this natively, but there does not seem to be an API.
Should I be trying to perform transactions with my own SQL statements (“BEGIN IMMEDIATE” etc)?
Also is D1 strongly consistent? The docs mention that there are “read replicas”, but no mention of consistency or if that is a future feature and the current alpha actually routes requests to the same worker?
The alpha does not currently support traditional transactions.
When (not yet!) we deploy read replicas, our plan is to offer session consistency (effectively causal consistency): a Worker that queries D1 can read its own writes and otherwise observe its own mutations. “Strongly consistent” means different things to different people, but in a distributed system it will have a significant toll on performance.
Any chance we could request a future feature for strong consistency as an option for a database (knowing it’ll impact performance)? And/or achieve it in a way similar to AWS DynamoDB where you can designate individual queries as strong or not when making them?