Skip to content

Commit b339d84

Browse files
authored
Merge pull request #118 from Tcode-Motion/perf-sqlite-prepared-stmts-17869921331340859522
⚡ Optimize SQLite operations using statement caching
2 parents e35ac9b + 68c8588 commit b339d84

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎stdlib/src/sqlite.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,14 @@ impl StdlibRegistry {
9393
CONNECTIONS.with(|m| {
9494
let mut map = m.borrow_mut();
9595
if let Some(conn) = map.get_mut(&id) {
96-
conn.execute(&sql, rusqlite::params_from_iter(params))
96+
let mut stmt = conn.prepare_cached(&sql).map_err(|e| {
97+
RuntimeError::new(
98+
RuntimeErrorKind::InvalidOperation(e.to_string()),
99+
None,
100+
None,
101+
)
102+
})?;
103+
stmt.execute(rusqlite::params_from_iter(params))
97104
.map_err(|e| {
98105
RuntimeError::new(
99106
RuntimeErrorKind::InvalidOperation(e.to_string()),
@@ -161,7 +168,7 @@ impl StdlibRegistry {
161168
let rows = CONNECTIONS.with(|m| {
162169
let mut map = m.borrow_mut();
163170
if let Some(conn) = map.get_mut(&id) {
164-
let mut stmt = conn.prepare(&sql).map_err(|e| {
171+
let mut stmt = conn.prepare_cached(&sql).map_err(|e| {
165172
RuntimeError::new(
166173
RuntimeErrorKind::InvalidOperation(e.to_string()),
167174
None,

0 commit comments

Comments
 (0)