-
Notifications
You must be signed in to change notification settings - Fork 336
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
Introduce StatementCache #113
Conversation
…wenn-stmt-cache
statements from returning to the cache.
@@ -1,5 +1,7 @@ | |||
# Version UPCOMING (...) | |||
|
|||
* Adds a `cache` Cargo feature that provides `cache::StatementCache` for caching prepraed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here: prepared
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 fixed
Maybe you should wait before merging this PR. |
I don't think we can offer an API exactly like that. Their statement handles (the inner pub fn prepare_cached(&self, sql: &str) -> Result<CachedStatement> but since we can't clone, we have to give something different than the |
@gwenn Pushed some fairly significant changes to this branch, trying to present an API more like the one you linked from rust-postgres. The relevant user-facing bits are in the |
The column_count cannot be saved in memory because it can be invalidated by a DDL: db.execute("CREATE TABLE test (x TEXT)").unwrap();
// ...
let stmt = db.prepare_cached("SELECT * FROM test").unwrap();
// ...
db.execute("ALTER TABLE test ADD COLUMN y TEXT").unwrap();
// ...
stmt.stmt.query_map(&[], |row| {
let x = row.get(0);
let y = row.get(1); // PANIC ?
// ...
}).unwrap(); More precisely, only the Rows/Row can kept the column_count in memory (not the Statement). |
Nice catch! Added that test and a fix in 74b57ee. Notice any other issues? |
No other issue. |
Mostly #61, with fixes for the latest merged PRs.
@gwenn I made a couple of minor changes here; the only public-facing one is removing
cacheable
and instead having a consuming methoddiscard()
. I think this feels a little nicer; what do you think?