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

Conversation

@scouten
Copy link

@scouten scouten commented Feb 12, 2017

Also adds a new function call prepare which prepares the SQL statement, adds it to the cache, and returns information about the query to the calling process. To protect encapsulation across processes, it does not return any direct reference to the prepared statement itself.

@mmmries
Copy link
Collaborator

mmmries commented Feb 13, 2017

Thanks for the PR! Can you provide some context on the use-case for this cache? I would hazard a guess that it's performance related, but I haven't used this library in any high-volume applications so I don't have any context for why this helps with performance.

@obmarg
Copy link
Collaborator

obmarg commented Feb 13, 2017

Should we document how to use a statement that has been prepared by Sqlitex.Server.prepare?

It looks from the code that I would need to call prepare with the SQL string and then any future calls to query with that same SQL string will use the pre-prepared statement. Seems like a reasonable way to do it, but it's not the way I'd have initially expected things to work. Generally would have expected that calling prepare returns something that I later use to call that prepared statement.

Maybe a docstring on the prepare function could help make things a bit more obvious?

@scouten
Copy link
Author

scouten commented Feb 13, 2017

Yes, that makes sense. I'll add such documentation later today or tomorrow. (I'm at work today and this project lives on my personal laptop, which is at home.)

@scouten
Copy link
Author

scouten commented Feb 14, 2017

@mmmries This is here to support the sqlite_ecto2 effort. Ecto really really wants to have the summary information about the prepared statement and also the signal about whether the statement would compile at all when it calls the DbConnection prepare callback.

I tried using the Sqlitex module directly in my DbConnection implementation, but that led to a different set of issues (crashes in the esqlite NIF functions when my process was killed). I believe using the Server module instead will help if not completely resolve that issue.

@scouten
Copy link
Author

scouten commented Feb 14, 2017

@obmarg Agree that the "typical" definition of prepare would be to return some sort of reference to the prepared statement (as, for instance, the non-Server module in Sqlitex does). I wasn't able to come up with an approach to passing back reference that didn't carry with it a risk of leaving dangling references around. Caching a pre-determined number of queries seemed like a lesser evil.

@scouten
Copy link
Author

scouten commented Feb 14, 2017

@obmarg Added docstring on start_link/2 and prepare/3 so hopefully future readers won't be confused. :-)

@mmmries mmmries merged commit 42655f6 into elixir-sqlite:master Feb 15, 2017
@mmmries
Copy link
Collaborator

mmmries commented Feb 15, 2017

Thanks @scouten for working on the ecto side of things. Hopefully the usage of Server resolves your concurrency issues in ecto

@mmmries
Copy link
Collaborator

mmmries commented Feb 15, 2017

released as 1.2.0 🎉 💙 💚 ❤️ 💛

@scouten scouten deleted the server+prepared-stmt-cache branch February 18, 2017 01:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants