pub struct DatabaseBuilder<T: DatabaseSpec> { /* private fields */ }Expand description
빌더 (명세 §5.4)
Implementations§
Source§impl<T: DatabaseSpec> DatabaseBuilder<T>
impl<T: DatabaseSpec> DatabaseBuilder<T>
Sourcepub fn sqlite(self, path: impl Into<PathBuf>) -> Self
pub fn sqlite(self, path: impl Into<PathBuf>) -> Self
Sets the SQLite file path. The special :memory: path uses the same
single regular connection setup as Self::in_memory.
Sourcepub fn in_memory(self) -> Self
pub fn in_memory(self) -> Self
In-memory database for tests.
In-memory databases use one regular read/write connection regardless
of Self::connections. This serializes transactions and avoids
SQLite shared-cache SQLITE_LOCKED failures. With the live feature,
the notifier still owns its separate internal connection.
Sourcepub fn connections(self, n: usize) -> Self
pub fn connections(self, n: usize) -> Self
Sets the number of read/write connections in the unified pool.
In-memory databases always use one regular connection.
Sourcepub fn busy_timeout(self, d: Duration) -> Self
pub fn busy_timeout(self, d: Duration) -> Self
SQLITE_BUSY 대기 — 프로세스 내(통합 풀 동시 write)·외부 프로세스 write 경합 공용 (명세 §10)
Sourcepub fn queue_timeout(self, d: Duration) -> Self
pub fn queue_timeout(self, d: Duration) -> Self
커넥션 풀 대기 타임아웃 — 초과 시 Error::QueueTimeout
Sourcepub fn migrate(self, policy: MigrationPolicy) -> Self
pub fn migrate(self, policy: MigrationPolicy) -> Self
마이그레이션 정책
Sourcepub fn migrations(self, ms: impl IntoIterator<Item = Migration>) -> Self
pub fn migrations(self, ms: impl IntoIterator<Item = Migration>) -> Self
마이그레이션 스텝 일괄 등록 — migrations_dir! 산출물 등
Sourcepub fn auto_migrate(self, on: bool) -> Self
pub fn auto_migrate(self, on: bool) -> Self
Opt-in automatic migration from embedded snapshots (spec §8.4, decision 21d, default off).
When enabled, gaps in the registered migration chain are filled by
diffing consecutive embedded snapshots
(DatabaseSpec::EMBEDDED_SCHEMAS). Only safe operations are
executed automatically (CREATE TABLE, nullable ADD COLUMN, valid
RENAME COLUMN, CREATE INDEX). A gap whose diff contains destructive
changes fails with a clear Error::Migration instead — register a
manual step or use
fallback_to_destructive_migration.
Registered steps always take precedence over synthesized ones.
Sourcepub fn fallback_to_destructive_migration(self, enable: bool) -> Self
pub fn fallback_to_destructive_migration(self, enable: bool) -> Self
파괴적 마이그레이션 폴백 (명세 §8, 기본 off) — 체인이 불충분하면 모든 테이블을 삭제하고 현재 스키마로 재생성한다.
Sourcepub fn on_create(
self,
f: impl Fn(&Connection) -> Result<()> + Send + Sync + 'static,
) -> Self
pub fn on_create( self, f: impl Fn(&Connection) -> Result<()> + Send + Sync + 'static, ) -> Self
최초 생성 시 1회 콜백 (테이블 생성 직후).
Runs inside the schema-creation transaction (L-5): if the callback
fails, the schema DDL and user_version roll back together, so the
next open retries creation from scratch. Do not manage transactions
(BEGIN/COMMIT) inside the callback.
Sourcepub fn on_open(
self,
f: impl Fn(&Connection) -> Result<()> + Send + Sync + 'static,
) -> Self
pub fn on_open( self, f: impl Fn(&Connection) -> Result<()> + Send + Sync + 'static, ) -> Self
오픈 시마다 콜백