Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Would you consider implementing server side statements #105

Open
lud opened this issue Jan 19, 2021 · 3 comments
Open

Would you consider implementing server side statements #105

lud opened this issue Jan 19, 2021 · 3 comments

Comments

@lud
Copy link

lud commented Jan 19, 2021

Hi,

I do not know if you know the depo elixir package, but it has an interesting feature.

This feature may be implemented in the Sqlitex.Server module.

Basically, you create a statement with a name. So instead of calling Sqlitex.Server.prepare(:example, "SELECT * FROM t") you would call Sqlitex.Server.register_statement(:example, :all_from_t, "SELECT * FROM t").

And now, you could call the statement with Sqlitex.Server.query(:example, :all_from_t)

The point is to liberate the user from the statements bookeeping as users do not need to keep the statement variable around, neither the SQL query binary. Plus, as the statement is only visible in the db server, it cannot be messed with by another process.

What do you think ?

@ConnorRigby
Copy link
Member

I like this idea and have never considered it before. I haven't had a ton of time to work on this project lately, but when i get some time i'd love to take a crack at it. I've added the help wanted tag to it, so anyone reading this in the future should feel free to try their hand at implementing it as well.

@lud
Copy link
Author

lud commented Jan 20, 2021

Hi,

I'm glad that you like the idea!

I will give it a try in the near future too, but I was thinking of writing a complete alternative server module instead of modifying the current one. I am not sure I would not break the current one.

@lud
Copy link
Author

lud commented Jan 23, 2021

I made a proof of concept here with a simple statement cache for well-known queries.

It works in transactions too. Though I changed a little bit the way transactions work in my version, but that should not make a a difference if you want to implement the same thing in the current server implementation. It was because at some point I had a throw in some transaction, and I discovered that throws make a genserver's handle_call return early. I was not aware of that and it took me some time to figure that out.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants