Skip to main content

SqliteStorage

Struct SqliteStorage 

Source
pub struct SqliteStorage { /* private fields */ }
Expand description

SQLite-backed storage implementation.

Wraps an r2d2 connection pool. Use new for file-backed storage or new_in_memory for testing with isolated in-memory databases.

Implementations§

Source§

impl SqliteStorage

Source

pub fn new(path: &Path) -> Result<Self, StorageError>

Opens a file-backed SQLite database at path.

§Errors

Returns StorageError::Connection if the database file cannot be opened or the pool cannot be created.

Source

pub fn new_in_memory() -> Result<Self, StorageError>

Opens an in-memory SQLite database with shared cache.

Suitable for testing — each call creates an isolated database.

§Errors

Returns StorageError::Connection if the pool cannot be created.

Trait Implementations§

Source§

impl Clone for SqliteStorage

Source§

fn clone(&self) -> SqliteStorage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SqliteStorage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl SeedManager for SqliteStorage

Source§

fn seed_init<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<SeedStatus, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Initialize seed data from the embedded fallback (compile-time JSON). Read more
Source§

fn seed_refresh<'life0, 'life1, 'async_trait>( &'life0 self, url: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<SeedStatus, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch and apply seed data from a remote URL. Read more
Source§

fn seed_status<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<SeedStatus, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Query the current seed data status without fetching.
Source§

fn seed_check_remote<'life0, 'life1, 'async_trait>( &'life0 self, url: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<SeedStatus, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch the remote manifest and compare with local status, but do NOT apply any changes. Used by the admin API ?remote=true query parameter.
Source§

impl Storage for SqliteStorage

Source§

fn list_providers<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Provider>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all providers.
Source§

fn get_provider<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Provider>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a single provider by ID.
Source§

fn list_models<'life0, 'life1, 'async_trait>( &'life0 self, provider_id: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Model>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List models, optionally filtered by provider.
Source§

fn get_model<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Model>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a single model by ID.
Source§

fn list_channels<'life0, 'life1, 'async_trait>( &'life0 self, model_id: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Channel>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List all channels, optionally filtered by model ID.
Source§

fn get_channel<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Channel>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a single channel by ID.
Source§

fn upsert_channel<'life0, 'life1, 'async_trait>( &'life0 self, channel: &'life1 Channel, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Insert or replace a channel (upsert).
Source§

fn set_channel_enabled<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, enabled: bool, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Toggle a channel enabled/disabled.
Source§

fn set_channel_api_key<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, key: &'life2 SecretString, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Update just the API key for a channel.
Source§

fn update_channel<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>( &'life0 self, id: &'life1 str, name: Option<&'life2 str>, enabled: Option<bool>, priority: Option<u32>, monthly_quota: Option<u64>, quota_policy: Option<&'life3 str>, protocols: Option<&'life4 str>, force_protocol: Option<&'life5 str>, ) -> Pin<Box<dyn Future<Output = Result<Channel, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, 'life5: 'async_trait,

Update channel fields (name, enabled, priority, quota, protocols, force_protocol).
Source§

fn delete_channel<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a channel and its model mappings (cascade).
Source§

fn mark_channel_healthy<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Mark a channel as healthy (reset failures).
Source§

fn record_channel_failure<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Record a channel failure (increments counter, may set Degraded/Cooldown).
Source§

fn list_mappings<'life0, 'life1, 'async_trait>( &'life0 self, channel_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ModelMapping>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List all model mappings for a channel.
Source§

fn upsert_mapping<'life0, 'life1, 'async_trait>( &'life0 self, mapping: &'life1 ModelMapping, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Upsert a single model mapping.
Source§

fn set_mapping_enabled<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, enabled: bool, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Toggle a model mapping enabled/disabled.
Source§

fn delete_mapping<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a model mapping.
Source§

fn list_all_mappings<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ModelMapping>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all model mappings.
Source§

fn insert_cost_record<'life0, 'life1, 'async_trait>( &'life0 self, record: &'life1 CostRecord, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Record a completed request.
Source§

fn query_cost_records<'life0, 'async_trait>( &'life0 self, filter: CostFilter, ) -> Pin<Box<dyn Future<Output = Result<Vec<CostRecord>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Query cost records with optional filters.
Source§

fn aggregate_costs<'life0, 'async_trait>( &'life0 self, group_by: CostGroupBy, range: TimeRange, ) -> Pin<Box<dyn Future<Output = Result<Vec<CostAggregate>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Aggregate costs grouped by the given dimension within a time range.
Source§

fn prune_cost_records<'life0, 'async_trait>( &'life0 self, older_than_days: u32, ) -> Pin<Box<dyn Future<Output = Result<u64, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Delete records older than N days, returning the count of deleted rows.
Source§

fn list_projects<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List distinct project paths from cost records, sorted alphabetically.
Source§

fn insert_switch_log<'life0, 'life1, 'async_trait>( &'life0 self, log: &'life1 SwitchLog, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Record a channel switch event.
Source§

fn insert_subscription_fee<'life0, 'life1, 'async_trait>( &'life0 self, fee: &'life1 SubscriptionFee, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Record a monthly subscription fee.
Source§

fn query_subscription_fees<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, channel: Option<&'life1 str>, month: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<Vec<SubscriptionFee>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Query subscription fees optionally filtered by channel and/or month.
Source§

fn query_switch_logs<'life0, 'async_trait>( &'life0 self, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<SwitchLog>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Query recent switch logs, optionally limited.
Source§

fn list_available_channels<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<AvailableChannelInfo>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all enabled channels with their bound models. Used by token-fleet-switch for Claude direct-connect mode.
Source§

fn migrate<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Run migrations / schema init. Idempotent — safe to call on every startup.
Source§

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<bool, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Health check — returns true if the backend is reachable.
Source§

fn max_connections(&self) -> usize

Maximum number of concurrent connections this backend supports.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more