Skip to main content

DatabaseBuilder

Struct DatabaseBuilder 

Source
pub struct DatabaseBuilder<T: DatabaseSpec> { /* private fields */ }
Expand description

빌더 (명세 §5.4)

Implementations§

Source§

impl<T: DatabaseSpec> DatabaseBuilder<T>

Source

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.

Source

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.

Source

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.

Source

pub fn busy_timeout(self, d: Duration) -> Self

SQLITE_BUSY 대기 — 프로세스 내(통합 풀 동시 write)·외부 프로세스 write 경합 공용 (명세 §10)

Source

pub fn queue_timeout(self, d: Duration) -> Self

커넥션 풀 대기 타임아웃 — 초과 시 Error::QueueTimeout

Source

pub fn migrate(self, policy: MigrationPolicy) -> Self

마이그레이션 정책

Source

pub fn migration(self, m: Migration) -> Self

마이그레이션 스텝 등록 (명세 §8.2/§8.3) — 세 소스 공통 표현

Source

pub fn migrations(self, ms: impl IntoIterator<Item = Migration>) -> Self

마이그레이션 스텝 일괄 등록 — migrations_dir! 산출물 등

Source

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.

Source

pub fn fallback_to_destructive_migration(self, enable: bool) -> Self

파괴적 마이그레이션 폴백 (명세 §8, 기본 off) — 체인이 불충분하면 모든 테이블을 삭제하고 현재 스키마로 재생성한다.

Source

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.

Source

pub fn on_open( self, f: impl Fn(&Connection) -> Result<()> + Send + Sync + 'static, ) -> Self

오픈 시마다 콜백

Source

pub fn query_logger( self, f: impl Fn(&str, Duration) + Send + Sync + 'static, ) -> Self

쿼리 로거 — (sql, 소요시간)

Source

pub fn build(self) -> Result<T>

DB 오픈 — PRAGMA 초기화 · 스냅샷 스테일 검증 · 마이그레이션 · 풀 구성 (명세 §5.4)

Trait Implementations§

Source§

impl<T: DatabaseSpec> Default for DatabaseBuilder<T>

Source§

fn default() -> Self

기본값 — 커넥션 수는 CPU 코어 기반(최대 4), busy_timeout 5초

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for DatabaseBuilder<T>

§

impl<T> !UnwindSafe for DatabaseBuilder<T>

§

impl<T> Freeze for DatabaseBuilder<T>

§

impl<T> Send for DatabaseBuilder<T>
where T: Send,

§

impl<T> Sync for DatabaseBuilder<T>
where T: Sync,

§

impl<T> Unpin for DatabaseBuilder<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for DatabaseBuilder<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.