A database's life across runs: opened from the last run's manifest, committed back to it, closed.
session =
Roux.Session.open(
modules: [MyTool.Graph],
manifest: "_build/dev/my_tool.manifest",
blob: "~/.cache/my_tool/store"
)
try do
%{meta: meta} = Roux.Sources.sync(session.db, :file, files, session.sources)
results = MyTool.Graph.run(session.db)
Roux.Session.commit(session, meta, extra: summary(results))
after
Roux.Session.close(session)
endopen/1 registers the modules (and languages) first and restores the
manifest after, so a restore sees every query it may keep
(Roux.Lang.Manifest.restore/2). commit/3 writes the manifest only
when the run changed something it would hold — an input set, an
entry computed, the sources' metadata moved — so a run that changed
nothing writes nothing. The manifest leaves out what the queries say
not to keep (Roux.Query's store: and transient:, with every
entry that read a transient one) and retains in the blob store what
it names. A small extra term goes beside it, readable without
loading the manifest (read_extra/1): what a Mix compiler's
diagnostics/0 returns, say.
Summary
Types
An open session: its database, the manifest it came from and goes to
(nil for none), its blob store (nil for none), the sources' metadata
the manifest held (%{} on a cold start), and whether it restored
one.
Functions
Closes a session: drops the values the calling process cached while
serving its queries, shuts its database down, and removes its blob
store when it was a temporary one (Roux.Blob.temporary/0).
Writes the session's manifest, with sources as its sources'
metadata, when the run changed anything it holds: an input set or
removed, an entry computed, or other sources' metadata than it
restored. A session that restored nothing always writes. Returns
whether it wrote, and the session as committed: committing it again
writes only what changed since.
The files a Mix compiler reports as its manifests for a session's
manifest at manifest: the manifest and its extra sidecar.
Opens a session.
The extra term a session committed beside the manifest at
manifest (commit/3), or :error when there is none, or it does
not decode.
Types
@type t() :: %Roux.Session{ blob: Roux.Blob.t() | nil, db: Roux.Database.t(), manifest: Path.t() | nil, restored?: boolean(), revision: Roux.Revision.revision(), sources: map(), writes: non_neg_integer() }
An open session: its database, the manifest it came from and goes to
(nil for none), its blob store (nil for none), the sources' metadata
the manifest held (%{} on a cold start), and whether it restored
one.
Functions
@spec close(t()) :: :ok
Closes a session: drops the values the calling process cached while
serving its queries, shuts its database down, and removes its blob
store when it was a temporary one (Roux.Blob.temporary/0).
Writes the session's manifest, with sources as its sources'
metadata, when the run changed anything it holds: an input set or
removed, an entry computed, or other sources' metadata than it
restored. A session that restored nothing always writes. Returns
whether it wrote, and the session as committed: committing it again
writes only what changed since.
Options
:extra— a small term to keep beside the manifest (read_extra/1), written when it differs from the one there.
The files a Mix compiler reports as its manifests for a session's
manifest at manifest: the manifest and its extra sidecar.
Opens a session.
Options
:modules— modules of queries (use Roux.Query) to register (Roux.Lang.register_module/2);:languages— languages to register (Roux.Lang.register/2);:manifest— the manifest to restore from and commit to; nil (the default) for a session that keeps nothing;:blob— aRoux.Blobstore, or the root of one: wherestore: :blobvalues and code versions are kept;:force— true to start cold, ignoring the manifest (it is still written on commit).
The extra term a session committed beside the manifest at
manifest (commit/3), or :error when there is none, or it does
not decode.