# Snapshots

> UStore for Mojo

`from ustore import Snapshot`

## Snapshot

A point-in-time state of the whole database, released when it goes out of scope. It pins the versions its reads need and holds its database open.

```mojo
struct Snapshot
```

Verbs called on it read at its state on the calling thread; writes, carrying no transaction, land
at the head. `snap.on(executor)` and `snap.deferred(executor)` route the same verbs to an executor.

- `library` `Library`: The loaded engine.
- `database` `Address`: The `ustore_database_t` it belongs to.
- `address` `Address`: The opaque `ustore_snapshot_t`.
- `read_stamp` `Stamp`: The stamp the snapshot reads at.

Conforms to: `BlobsVerbs`, `DatabaseVerbs`, `Deinitable`, `DocsVerbs`, `GraphVerbs`, `Movable`, `PagesVerbs`, `StringsVerbs`

## __init__

Adopts a snapshot the engine just pinned.

```mojo
def __init__(out self, *, library: Library, database: Int, address: Int, read_stamp: Stamp)
```

## __deinit__

Releases the snapshot. Calls `ustore_snapshot_free`.

```mojo
def __deinit__(deinit self)
```

## on

The same verbs, blocking on `executor`. Binding-only.

```mojo
def on(ref self, ref executor: Executor) -> On[origin_of(executor, self)]
```

## deferred

The same verbs, each submitted to `executor` and answering a [`Deferred`](https://www.unum.cloud/docs/ustore/mojo/batches-and-arenas.md#Deferred) at once. Binding-only.

```mojo
def deferred(ref self, ref executor: Executor) -> DeferredOn[origin_of(executor, self)]
```

