Skip to main content

SqliteBackend

Struct SqliteBackend 

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

SQLite-backed state store for local development.

Run migrations with SqliteBackend::migrate before first use.

Implementations§

Source§

impl SqliteBackend

Source

pub async fn connect(database_url: &str) -> Result<Self, Error>

Connect to the SQLite database at database_url and return a backend. database_url is a SQLx-compatible URL, e.g. sqlite:///path/to/db.sqlite3. The database file is created automatically if it does not exist.

Source

pub async fn migrate(&self) -> Result<(), MigrateError>

Run embedded migrations against the connected database.

Source

pub async fn open( database_url: &str, ) -> Result<Self, Box<dyn Error + Send + Sync>>

Convenience: connect and immediately run migrations.

Source

pub fn for_tenant(&self, tenant_id: TenantId) -> TenantScopedSqliteBackend

Create a tenant-scoped view of this backend.

All operations on the returned backend are filtered by tenant_id, ensuring complete data isolation between tenants.

Source

pub fn pool(&self) -> SqlitePool

Get a clone of the underlying connection pool.

Trait Implementations§

Source§

impl StateBackend for SqliteBackend

Source§

fn store_workflow<'life0, 'async_trait>( &'life0 self, def: WorkflowDefinition, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Store a compiled workflow IR.
Source§

fn get_workflow<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, workflow_id: &'life1 str, version: &'life2 str, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<WorkflowDefinition>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Load a workflow definition by id and version.
Source§

fn create_execution<'life0, 'async_trait>( &'life0 self, execution: WorkflowExecution, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create a new workflow execution record.
Source§

fn get_execution<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<WorkflowExecution>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load a workflow execution by id.
Source§

fn update_execution_status<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ExecutionId, status: WorkflowStatus, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update the status of a workflow execution.
Source§

fn update_execution_current_state<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 ExecutionId, current_state: &'life2 Value, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Update the current_state of a workflow execution (apply state patches).
Source§

fn patch_append_array<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, key: &'life2 str, value: Value, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Append a value to an array field in the execution’s current_state. Creates the array if it doesn’t exist.
Source§

fn list_executions<'life0, 'async_trait>( &'life0 self, status: Option<WorkflowStatus>, limit: u32, offset: u32, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<WorkflowExecution>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List executions, optionally filtered by status.
Source§

fn append_event<'life0, 'async_trait>( &'life0 self, event: Event, ) -> Pin<Box<dyn Future<Output = BackendResult<EventSequence>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Append an event to the event log. Must be transactional — either fully written or not at all.
Source§

fn get_events<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<Event>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load all events for an execution, ordered by sequence.
Source§

fn get_events_since<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, since_sequence: EventSequence, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<Event>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load events since a given sequence number (exclusive).
Source§

fn latest_sequence<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<EventSequence>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get the latest event sequence for an execution.
Source§

fn write_snapshot<'life0, 'async_trait>( &'life0 self, snapshot: Snapshot, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Write a snapshot.
Source§

fn latest_snapshot<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<Snapshot>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load the latest snapshot for an execution.
Source§

fn enqueue_work_item<'life0, 'async_trait>( &'life0 self, item: WorkItem, ) -> Pin<Box<dyn Future<Output = BackendResult<WorkItemId>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Enqueue a work item for execution.
Source§

fn claim_work_item<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, worker_id: &'life1 str, queue_types: &'life2 [&'life3 str], ) -> Pin<Box<dyn Future<Output = BackendResult<Option<WorkItem>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Claim the next available work item for a given queue type. Returns None if no items are available.
Source§

fn renew_lease<'life0, 'life1, 'async_trait>( &'life0 self, item_id: WorkItemId, worker_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Renew the lease on a claimed work item (heartbeat).
Source§

fn complete_work_item<'life0, 'async_trait>( &'life0 self, item_id: WorkItemId, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Mark a work item as completed and release the lease.
Source§

fn fail_work_item<'life0, 'life1, 'async_trait>( &'life0 self, item_id: WorkItemId, error: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Mark a work item as failed. The scheduler will decide whether to retry.
Source§

fn reclaim_expired_leases<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = BackendResult<ReclaimResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reclaim work items whose lease has expired (worker crashed or stalled). Read more
Source§

fn move_to_dead_letter<'life0, 'life1, 'async_trait>( &'life0 self, item_id: WorkItemId, last_error: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Move a failed work item to the dead-letter queue.
Source§

fn create_token<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, name: &'life1 str, role: &'life2 str, ) -> Pin<Box<dyn Future<Output = BackendResult<(String, ApiToken)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Create a new API token. Returns (plaintext_token, token_info). The plaintext token is only returned here; only its hash is stored.
Source§

fn validate_token<'life0, 'life1, 'async_trait>( &'life0 self, token: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<ApiToken>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Validate a plaintext API token. Returns the token info if valid and not revoked.
Source§

fn create_tenant<'life0, 'async_trait>( &'life0 self, _tenant: Tenant, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create a new tenant.
Source§

fn get_tenant<'life0, 'life1, 'async_trait>( &'life0 self, _id: &'life1 TenantId, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<Tenant>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a tenant by ID.
Source§

fn list_tenants<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<Tenant>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all tenants.
Source§

fn update_tenant<'life0, 'async_trait>( &'life0 self, _tenant: Tenant, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Update tenant metadata (name, status, policy, limits).

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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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