better_duck_core::database::Database (re-exported as better_duck_core::Database) is a shared,
cloneable handle to one open DuckDB database. Open it once, then connect() as many
Connections as you need — all observing the same data.
Why Database exists
A bare Connection::open_in_memory() creates a database private to that one connection — a
second such call is a different database. Database is how you get the “one database, many
connections” topology, which is essential for in-memory databases (where there is no file to
re-open) and is the foundation of the pool.
Each connection made from a
Database has its own transaction scope (a fresh
duckdb_connect). Writes become visible to other connections once committed, following DuckDB’s
normal transaction semantics.Constructors
Database mirrors the Connection constructors:
Open (or create) an on-disk database.
Open a shared in-memory database.
Open a new connection to this database.
Lifetime and cheap cloning
DatabaseisClone(a cheapArcbump),Send + Sync, and implementsDebug.- The backing database outlives every handle: a live connection keeps it open even after every
Databasehandle is dropped.
Bridging from a connection
Already have aConnection? Call Connection::database()
to get a Database for its backing database, then connect() more connections.
See also
- Opening connections — single-connection lifecycle and
try_clone. - Pooling — an r2d2 pool is built on exactly this shared-database model.
- Async —
AsyncDatabaseis the async mirror of this type.