API Reference

rusqlite

Ergonomic SQLite bindings for Rust with prepared statements, transactions and parameter binding.

Official Documentation ↗
CompatibilityThis documentation covers version rusqlite 0.32 / 捆绑 SQLite 或系统库 / Rust 1.70+. Check the official docs for the latest API surface.

Installation

cargocargo add rusqlite

Methods

Overview

rusqlite wraps SQLite for Rust with safe, ergonomic APIs for connections, prepared statements and transactions, avoiding raw C FFI while keeping SQLite behavior.

Core Methods

Open a connection, prepare statements, and execute with parameters. query_row maps a row to a Rust value, and transactions ensure atomic changes. Features select bundled SQLite or extensions.

Usage Notes

Prepare statements once and reuse them, wrap multi-step writes in transactions, and enable WAL for read-heavy concurrency. Always bind parameters rather than formatting SQL.

Common Pitfalls

Not committing a transaction rolls it back on drop, which can silently discard work. Sharing one connection across threads is unsafe. Missing indexes on scanned columns slows queries even on embedded SQLite.

Errors

The following points are quoted verbatim from the official documentation (https://docs.rs/rusqlite/latest/rusqlite/). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

Should I bundle SQLite or link the system library?
Bundling compiles a known SQLite version for reproducible builds, while linking the system library reduces build time but depends on the installed version and features.
How are parameters bound?
Use the params! macro or a slice of ToSql values with ?1 numbered or ? positional placeholders, which prevents injection and enables statement reuse.
How do I handle connection sharing across threads?
A Connection is not Send for concurrent use unless created with the appropriate flags. Use a pool or open a connection per thread, and enable WAL for better concurrency.