Skip to main content
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.
As open, with a Config.
As open_in_memory, with a Config.
Open a new connection to this database.

Lifetime and cheap cloning

  • Database is Clone (a cheap Arc bump), Send + Sync, and implements Debug.
  • The backing database outlives every handle: a live connection keeps it open even after every Database handle is dropped.

Bridging from a connection

Already have a Connection? 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 — AsyncDatabase is the async mirror of this type.