pub struct CoreDb { /* private fields */ }Expand description
Unified database for sessions, cron, and auth.
Owns a single SqlitePool backed by core.db. Individual stores
(SessionManager, CronStore, AuthStore) receive a clone of the
pool via from_pool() instead of opening their own connections.
The pool is configured with:
- WAL journal mode — concurrent readers don’t block writers
- Foreign keys ON — referential integrity across all tables
- 2 max connections — one writer + one reader; SQLite serialises writes anyway, so more connections just waste memory (~2 MB page cache each) and cause lock contention on small VMs
busy_timeout = 5000— wait up to 5 s for a lock instead of returning SQLITE_BUSY immediatelysynchronous = NORMAL— safe with WAL, avoids fsync per commitcache_size = -2000— 2 MB page cache per connection (default)
Implementations§
Source§impl CoreDb
impl CoreDb
Sourcepub async fn new(db_dir: &Path) -> Result<Self>
pub async fn new(db_dir: &Path) -> Result<Self>
Open (or create) core.db inside db_dir.
Runs all migrations from ./migrations. If migrations fail due to a
checksum mismatch or a removed migration (common during development
when migration files are edited in-place), the database is deleted
and recreated from scratch.
Sourcepub async fn in_memory() -> Result<Self>
pub async fn in_memory() -> Result<Self>
Create an in-memory CoreDb for testing.
Runs all migrations on a shared in-memory database. Each call returns a fresh, empty database.
Sourcepub fn pool(&self) -> &SqlitePool
pub fn pool(&self) -> &SqlitePool
Get a reference to the shared connection pool.
Auto Trait Implementations§
impl Freeze for CoreDb
impl !RefUnwindSafe for CoreDb
impl Send for CoreDb
impl Sync for CoreDb
impl Unpin for CoreDb
impl UnsafeUnpin for CoreDb
impl !UnwindSafe for CoreDb
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more