# Platform Notes

> DatabaseInitRam starts an empty database in memory alone, DatabaseOpenRam serves a directory as one image, DatabaseOpenRocksdb, DatabaseOpenLeveldb and DatabaseOpenNvme serve a directory in place, and DatabaseViewRocksdb and DatabaseViewNvme serve one read-only, refusing every change with StatusReadOnly.

`import "github.com/unum-cloud/ustore"` 1.0.0-rc.1 · 084197c4

### Engines

`DatabaseInitRam` starts an empty database in memory alone, `DatabaseOpenRam` serves a directory as one image, `DatabaseOpenRocksdb`, `DatabaseOpenLeveldb` and `DatabaseOpenNvme` serve a directory in place, and `DatabaseViewRocksdb` and `DatabaseViewNvme` serve one read-only, refusing every change with `StatusReadOnly`. `Close` writes nothing to disk, so `On(executor).Flush()` makes commits with `DurabilityBuffered` durable before it. `Describe` reports the engine, the isolation, the CPU class picked and the sizes the engine estimates, `Clear` empties every collection at once, and `Compact` reclaims space through the phases its engine runs, where a `CompactPlan` keeps a stopped compaction open until `CompactPlanFinish`. The RAM engine always links, and build tags mirror the Cargo features for the others: `ustore_rocksdb` links `librocksdb`, and on Linux `liburing` beside it, and `ustore_leveldb` links `libleveldb`. Build the archive with the matching `USTORE_WITH_*` options and point `CGO_LDFLAGS` at the directory holding the engine archives too, as the `lib/` of a prefix CMake installed with `USTORE_INSTALL` does; the NVMe engine links nothing more.

```sh
go build -tags ustore_rocksdb,ustore_leveldb ./...
```

With those tags, a scratch database in memory and a RocksDB directory open side by side, and either one describes, clears and compacts through the same calls:

```go
scratch, err := ustore.DatabaseInitRam(&ustore.DatabaseInitRamConfig{Isolation: ustore.IsolationSnapshot})
people, err := ustore.DatabaseOpenRocksdb("/var/lib/people", nil)
description, err := people.Describe()
err = people.Clear(ustore.DropValues) // keeps every key, emptying its value
err = people.Compact(nil)            // reclaims what overwritten and removed data still takes
```

### Left Unbound

- Deferred opens, transaction and snapshot inits, resets, cursor inits, cursor pulls and ingests: these block whatever receiver they are called on.
- The progress of a cursor pull, and the lengths a read writes beside its values, which the tape’s offsets carry.
- Batches of strings through an accessor: every input batch is a `Tape`.
- Exporting strided keys, like the columns of edges, through `KeysViewToArrow`, which takes dense keys alone.

### Design

- The receiver makes the completion a type, not a flag. Each verb is written once over its parent, and the parent decides what compiles: only a transaction commits, only the head clears and compacts, and nothing writes through a snapshot.
- Inputs cross as they lie. Keys, edges and tapes are pinned in place for the call, and a collection or a role the whole batch shares crosses from the call’s own frame, so nothing is staged on the way in.
- One pinned frame per call. It holds the outcome, the argument structure, the fixed-width inputs and the result, and `TestCallsAllocateOnlyTheirFrames` pins the budgets below.
- No life of its own. The binding starts no goroutines, takes no locks and keeps no counts or queues, and releasing a `Deferred` rides `Wait`, `Close` or the collector, each of which waits for the call to be final first.

| Path | Go | Rust |
| - | - | - |
| Blocking call | 1 frame | 0 |
| Refusal before the call | 1 `Error` | 1 error |
| Deferred submit and wait | 4: frame, `Deferred`, 2 in `AddCleanup` | 0 |
| Each callback | 1 handle | 0 |

## API

### Types

#### `PagesImportConfig`

PagesImportConfig carries the optional arguments of [DatabaseOn.PagesImport](https://www.unum.cloud/docs/ustore/go/transactions.md#PagesImport).

[db.go:74 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/db.go#L74)

```go
type PagesImportConfig struct {
    Encoding PageEncoding
    Durability Durability
    Progress ProgressCallback
}
```

#### Fields

| `Encoding` | `PageEncoding` | Encoding is the encoding of the markup. |
| - | - | - |
| `Durability` | `Durability` | Durability is how durable the edits are once the call finishes at the head. |
| `Progress` | `ProgressCallback` | Progress reports the pages parsed, and may cancel the call. |

#### `PagesInsertConfig`

PagesInsertConfig carries the optional arguments of [DatabaseOn.PagesInsert](https://www.unum.cloud/docs/ustore/go/transactions.md#PagesInsert).

[db.go:128 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/db.go#L128)

```go
type PagesInsertConfig struct {
    Elements []Key
    Parents []Key
    Anchors []Key
    Encoding PageEncoding
    Durability Durability
}
```

#### Fields

| `Elements` | `[]Key` | Elements are the keys to give the inserted elements, one per task, or keys minted for each when empty. |
| - | - | - |
| `Parents` | `[]Key` | Parents are the elements the fragments land under, one per task, the zero key for the root, or the root for every one when empty. |
| `Anchors` | `[]Key` | Anchors are the siblings after which the fragments land, one per task, the zero key for the front, or the front for every one when empty. |
| `Encoding` | `PageEncoding` | Encoding is the encoding of the fragments. |
| `Durability` | `Durability` | Durability is how durable the edits are once the call finishes at the head. |

#### `PagesMoveConfig`

PagesMoveConfig carries the optional arguments of [DatabaseOn.PagesMove](https://www.unum.cloud/docs/ustore/go/transactions.md#PagesMove).

[db.go:261 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/db.go#L261)

```go
type PagesMoveConfig struct {
    Parents []Key
    Anchors []Key
    Durability Durability
}
```

#### Fields

| `Parents` | `[]Key` | Parents are the elements the moved elements land under, one per task, the zero key for the root. |
| - | - | - |
| `Anchors` | `[]Key` | Anchors are the siblings after which the moved elements land, one per task, the zero key for the front. |
| `Durability` | `Durability` | Durability is how durable the edits are once the call finishes at the head. |

#### `PagesReadConfig`

PagesReadConfig carries the optional arguments of [DatabaseOn.PagesRead](https://www.unum.cloud/docs/ustore/go/batches-and-arenas.md#PagesRead).

[db.go:446 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/db.go#L446)

```go
type PagesReadConfig struct {
    Elements []Key
    OutputsEncoding PageEncoding
}
```

#### Fields

| `Elements` | `[]Key` | Elements are the elements to render with their subtrees, one per key, the zero key for the whole page, or whole pages when empty. |
| - | - | - |
| `OutputsEncoding` | `PageEncoding` | OutputsEncoding is the encoding the renderings are converted into. |

#### `PagesRemoveConfig`

PagesRemoveConfig carries the optional arguments of [DatabaseOn.PagesRemove](https://www.unum.cloud/docs/ustore/go/transactions.md#PagesRemove).

[db.go:208 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/db.go#L208)

```go
type PagesRemoveConfig struct {
    Elements []Key
    EndKeys []Key
    Durability Durability
}
```

#### Fields

| `Elements` | `[]Key` | Elements are the elements to remove with their subtrees, one per task. |
| - | - | - |
| `EndKeys` | `[]Key` | EndKeys turn every key into the inclusive start of a range of whole pages ending before its end key, one per task, which leaves Elements empty. |
| `Durability` | `Durability` | Durability is how durable the edits are once the call finishes at the head. |

#### `PagesScanConfig`

PagesScanConfig carries the optional arguments of [DatabaseOn.PagesScan](https://www.unum.cloud/docs/ustore/go/batches-and-arenas.md#PagesScan).

[db.go:502 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/db.go#L502)

```go
type PagesScanConfig struct {
    StartKeys []Key
    EndKeys []Key
    Direction ScanDirection
    Filter string
    Predicate Admitter
    Mode ScanMode
    Progress ProgressCallback
}
```

#### Fields

| `StartKeys` | `[]Key` | StartKeys are the inclusive starts of the scans, one per task, or the first page in Direction when empty. |
| - | - | - |
| `EndKeys` | `[]Key` | EndKeys are the keys every scan stops before, one per task, or no bound when empty. |
| `Direction` | `ScanDirection` | Direction is which way every scan goes from its start. |
| `Filter` | `string` | Filter is the expression every listed page matches, shared by every scan. |
| `Predicate` | `Admitter` | Predicate admits or passes over the listed keys. |
| `Mode` | `ScanMode` | Mode is in what order the keys come. |
| `Progress` | `ProgressCallback` | Progress reports the scans finished, and may cancel the call. |

#### Struct `Inserted`

Inserted is the key every inserted element ended up with, minted or given, readable until the arena serves another call.1

[pages.go:146 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/pages.go#L146)

```go
type Inserted struct {
    // contains filtered or unexported fields
}
```

##### `Keys`

Keys views the keys of the inserted elements in the arena, one per fragment.

[pages.go:153 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/pages.go#L153)

```go
func (inserted Inserted) Keys() []Key
```

#### Enum `PageEncoding`

PageEncoding is the encoding a page or a fragment is imported from or rendered into.2

[pages.go:42 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/pages.go#L42)

```go
type PageEncoding int32
```

#### Values

| `PageEncodingHTML` | | PageEncodingHTML is HTML, not yet imported. |
| - | - | - |
| `PageEncodingXML` | | PageEncodingXML is XML, with every element and attribute kept as written. |
| `PageEncodingMarkdown` | | PageEncodingMarkdown is Markdown, not yet imported. |
| `PageEncodingText` | | PageEncodingText is the text of every run in document order, with structure dropped. |
| `PageEncodingJSON` | | PageEncodingJSON is the element tree as JSON, not yet imported. |

##### `PageEncodingFromName`

PageEncodingFromName reads an encoding back from the spelling [PageEncoding.String](#String) renders.

[pages.go:63 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/pages.go#L63)

```go
func PageEncodingFromName(name string) (PageEncoding, error)
```

##### `String`

String renders the encoding as the library spells it.

[pages.go:58 ↗](https://github.com/unum-cloud/UStore/blob/084197c470a8c329d83051d880c71e7972b9e1b2/pages.go#L58)

```go
func (encoding PageEncoding) String() string
```
