Skip to main content

Store

Struct Store 

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

The trestle state: workspaces, their environments (each a draft and numbered, immutable revisions), instances and the host-wide slot leases, in one SQLite database (WAL mode, so readers never block the writer).

Several processes open the same file: the CLI and the desktop app see each other’s writes. A write waits for another process’s to finish. A Watcher notices commits made through other connections.

Implementations§

Source§

impl Store

Source

pub fn open_default() -> Result<Self>

Open (creating it if needed) the store in the state directory.

Source

pub fn open(path: &Path) -> Result<Self>

Open (creating it if needed) the store at path, and bring its schema up to SCHEMA_VERSION. Errors with Error::UnsupportedVersion for a newer schema rather than read it half-way.

Source

pub fn path(&self) -> &Path

The database file.

Source

pub fn create_workspace(&self, name: &str, mesh: bool) -> Result<Workspace>

Create a workspace called name.

Source

pub fn workspaces(&self) -> Result<Vec<Workspace>>

Every workspace, by name.

Source

pub fn workspace(&self, name: &str) -> Result<Option<Workspace>>

The workspace called name.

Source

pub fn workspace_by_id(&self, id: &WorkspaceId) -> Result<Workspace>

The workspace id.

Source

pub fn set_workspace_vars(&self, id: &WorkspaceId, vars: &VarSet) -> Result<()>

Replace the workspace’s vars.

Source

pub fn set_workspace_source( &self, id: &WorkspaceId, name: &str, config: Option<Value>, ) -> Result<()>

Set the config every instance of the workspace binds the source name with, or clear it (None).

Source

pub fn modify_vars<E: From<Error>>( &self, scope: &VarScope, f: impl FnOnce(&mut VarSet) -> Result<(), E>, ) -> Result<VarSet, E>

Change the vars scope names with f, in one write transaction, so a concurrent writer’s change to other vars of the same set is kept. Returns the vars as written.

Source

pub fn delete_workspace(&self, id: &WorkspaceId) -> Result<()>

Delete the workspace with all its environments, revisions, instances and leases.

Source

pub fn create_environment( &self, workspace: &WorkspaceId, name: &str, draft: Draft, ) -> Result<Environment>

Create the environment name in workspace, with draft as its draft and no revision yet. The draft’s env_name is set to name.

Source

pub fn environments(&self, workspace: &WorkspaceId) -> Result<Vec<Environment>>

The environments of workspace, by name.

Source

pub fn environment(&self, id: &EnvironmentId) -> Result<Environment>

The environment id.

Source

pub fn update_draft(&self, id: &EnvironmentId, draft: &Draft) -> Result<()>

Replace the environment’s draft. Its committed revisions are untouched. The draft’s env_name is kept as the environment’s name.

Source

pub fn modify_draft<E: From<Error>>( &self, id: &EnvironmentId, f: impl FnOnce(&mut Draft) -> Result<(), E>, ) -> Result<Draft, E>

Change the environment’s draft with f, in one write transaction, so two writers (the CLI and the app, say) never lose each other’s edits. The draft’s env_name is kept as the environment’s name. Returns the draft as written.

Source

pub fn set_environment_vars( &self, id: &EnvironmentId, vars: &VarSet, ) -> Result<()>

Replace the vars every revision of the environment sees.

Source

pub fn delete_environment(&self, id: &EnvironmentId) -> Result<()>

Delete the environment with its revisions, instances and their leases.

Source

pub fn commit_draft(&self, id: &EnvironmentId) -> Result<Revision>

Commit the environment’s draft as its next revision (numbered one past its head) and make it the head.

Source

pub fn revision(&self, env: &EnvironmentId, number: u32) -> Result<Revision>

Revision number of the environment.

Source

pub fn revisions(&self, env: &EnvironmentId) -> Result<Vec<Revision>>

Every revision of the environment, oldest first.

Source

pub fn create_instance( &self, env: &EnvironmentId, revision: u32, ) -> Result<Instance>

Create an instance of revision revision of the environment, stopped and without a slot.

Source

pub fn instance(&self, id: &InstanceId) -> Result<Instance>

The instance id.

Source

pub fn instances(&self) -> Result<Vec<Instance>>

Every instance on the host, oldest first.

Source

pub fn instances_of(&self, env: &EnvironmentId) -> Result<Vec<Instance>>

The instances of the environment, oldest first.

Source

pub fn set_desired(&self, id: &InstanceId, desired: Desired) -> Result<()>

Set whether the instance should be running.

Source

pub fn set_overrides(&self, id: &InstanceId, overrides: &VarSet) -> Result<()>

Replace the instance’s overrides.

Source

pub fn set_sources( &self, id: &InstanceId, sources: &[SourceBinding], ) -> Result<()>

Replace the overlay sources the instance takes.

Source

pub fn delete_instance(&self, id: &InstanceId) -> Result<()>

Delete the instance, releasing its slot.

Source

pub fn lease_slot(&self, instance: &InstanceId) -> Result<SlotLease>

Lease the instance the lowest slot no instance on the host holds, or return the one it already holds. Atomic across processes.

Source

pub fn release_slot(&self, instance: &InstanceId) -> Result<()>

Release the instance’s slot, if it holds one.

Source

pub fn leases(&self) -> Result<Vec<SlotLease>>

Every lease on the host, by slot.

Source§

impl Store

Source

pub fn import_workspace(&self, dir: &Path) -> Result<Workspace>

Import the workspace directory dir (a trestle-workspace.toml and one environment directory per member) as a new workspace. Each member becomes an environment whose draft is its env.toml and the module manifests it lists, committed as revision 1.

Slots are not imported: the store leases them per instance, host-wide. Nor is secrets.env: the store holds secret references, not values.

Source

pub fn export_instances( &self, instances: &[InstanceId], dir: &Path, ) -> Result<()>

Export instances (all of one workspace, each of a different environment) as a workspace directory in dir: a trestle-workspace.toml whose members sit on the slots the instances lease, and per member its revision’s env.toml and module manifests. In the exported directory trestle env render and docker compose up work as in any workspace.

Source

pub fn export_workspace( &self, workspace: &WorkspaceId, dir: &Path, ) -> Result<()>

Export the head revision of every environment of the workspace as a workspace directory in dir, as export_instances does. A member sits on the slot of an instance of its head when one holds a slot, else on the lowest slot no other member takes. Every environment needs a revision.

Source

pub fn export_revision( &self, env: &EnvironmentId, number: u32, dir: &Path, ) -> Result<()>

Export revision number of the environment as an environment directory in dir: its env.toml and module manifests. No instance is needed. Like any env.toml it carries no placement, so it renders as an environment on its own.

Source§

impl Store

Source

pub fn watcher(&self) -> Result<Watcher>

A Watcher for this store’s file.

Trait Implementations§

Source§

impl Debug for Store

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.