-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
More convenient transaction support #8
Comments
I spent a long time vetting out transaction convenience methods, and it boils down to how Swift works and what I wanted in the balance of complexity. I wanted to leave as little room possible in the convenience methods to make a mistake. Sometimes this requires more upfront design (and can be inconvenient), but I figured there are 2 paths to take:
The example you give is less common from what I've used transactions for, so I'd like to better understand the use-case and how to support it (I've generally used transactions for 1., two+-step foreign key application, and 2., cascading CHECK validation failures). I could add convenience/helper functions, but it would generally be the same as this: db.run("BEGIN DEFERRED TRANSACTION")
if /* condition */ {
/* run statement */
} else {
/* run other statement */
}
db.run("COMMIT TRANSACTION") // or ROLLBACK, depending on the logic What kind of code would be ideal for you? |
The use case is synchronising data from a remote API. The returned JSON is quite complex, with some values conditionally inserting extra rows, or checking if an object already exists locally, and so on. Using |
Everything is up for review and change. I just want to understand use cases before supporting them too early. I should write a post on how I designed the early API, but it boils down to this:
For me, having implicit error handling, flow control, and simple boolean logic makes code a lot more readable and maintainable, so I tend to err on the side of naïve legibility. |
Let me sleep on this, but so far I'm inclined to add a simple, alternative block-based API that requires you to return This isn't advertised, but statements are already Bool-savvy. If they are successful, they are true, otherwise false. (Another thing to add to the documentation bucket list.) |
I personally prefer the explicit |
Closed by c5881a8 |
Hi,
The transaction support is not that convenient IMO. It forces pre-generation of statements with no opportunity for logic inside the transaction.
That is, AFAICT, you can not perform a select inside the transaction then conditionally issue other statements based on the result. Or in fact, issue any kind of conditional statements.
It also makes decomposition of many statements into separate functions more difficult, forcing all functions to return Statements.
eg. I can not do this:
Is there any reason a more convenient form of transaction couldn't be supported?
The text was updated successfully, but these errors were encountered: