Skip to content

Query Data

Maryk stores support a range of query actions. Requests can run locally or be serialized and sent to a remote store.

Use Maryk’s typed request API as the main API for application reads, writes, history, and sync. Start with the requests in this guide. SQL is an optional layer for reporting, ad hoc queries, and tabular integrations; it is not required to use Maryk stores.

A Maryk query is a typed request object created from a RootDataModel.

val request = Person.get(key)
val response = store.execute(request)

The same request shape works against every store engine. That is why the CLI, App, Remote Store and embedded stores can share behavior.

Use:

  • Add, Change, Delete for writes.
  • Get when you know keys.
  • Scan when you need a range, filter, index order or page.
  • GetChanges / ScanChanges for object history.
  • GetUpdateHistory / ScanUpdateHistory for bounded, newest-first historical update entries.
  • GetUpdates / ScanUpdates for chronological sync.
  • executeFlow(...) for live views.
  • executeAtomic(...) for a fixed write set with initial-state guards.
  • transaction { ... } for serializable reads and ordered writes.

Use reference graphs with reads to fetch only the fields you need.

TaskRequest to start with
Insert a new objectModel.add(...)
Update known objectsModel.change(key.change(...))
Fetch by keyModel.get(key)
Browse a range or pageModel.scan(...)
Fetch only a few fieldsAdd select with a reference graph
Build a live viewexecuteFlow(Model.scanUpdates(...))
Inspect field historyModel.getChanges(...) or Model.scanChanges(...)
Page through record revisionsModel.getUpdateHistory(key, ...)
Browse historical update entriesModel.scanUpdateHistory(...)

Start with add, get, and scan. Add filters, ordering, reference graphs, and update streams when the access pattern needs them.

Atomic execution and transactions share the backend commit engine, but expose different contracts. Choose a fixed write set when values and guards are known; choose a transaction when reads determine the writes.

RequirementAtomic requestTransaction scope
Commit several models togetherYes, within one storeYes, within one store
ChecksAll guards and preconditions use the initial stateEach operation sees the preceding staged operations
Read and decide inside the boundaryExplicit record guards only; earlier application reads are outside itGet and Scan, including empty predicates, protected by a revision fence
Write the same record repeatedlyOnce per write setSeparate ordered requests
Hard deletionUnsupportedSupported
Savepoints and rollbackNo interactive staging lifecycleSupported before commit submission
Recover an uncertain commitResubmit the identical request and change-set IDResolve the retained transaction’s exact commit

For example, adding an observation and its report with known values fits an atomic request. Scanning for pending records and changing every match, while protecting the decision from concurrent insertions, requires a transaction. Atomic version guards protect selected records; they do not protect an earlier scan’s predicate.

Capabilities remain separate for custom adapters: inspect atomicCapabilities and transactionCapabilities for the operation you need. Built-in local engines provide both, and Remote advertises its backend’s capabilities. Neither API falls back to a sequence of ordinary writes when unsupported.

The optional SQL layer follows the same distinction: execute uses serializable autocommit, transaction supplies an interactive scope, and prepareAtomic retains preselected targets for an atomic write set.

Insert model values and inspect the per-record statuses. Ordinary multi-record adds can partially succeed.

See Add.

Change fields on existing records. Checks and ordered changes apply within each record mutation; use an explicit write boundary for several records.

See Change.

Soft-delete for later recovery, or hard-delete to erase retained values. A historical version cannot recover erased persistent rows.

See Delete.

Commit a known write set and its initial-state guards together. Retain the same request and ID to resolve an uncertain outcome.

See Atomic.

Fetch known keys, optionally with a projection, filter or retained historical version. Repeated keys preserve request order.

See Get.

Read a bounded page with filters, ordering and an opaque continuation cursor. A suitable key/index or explicit table-scan permission is required.

See Scan.

Read retained field revisions. Multiple versions require keepAllVersions; ScanChanges restricts filters and ordering to immutable paths.

See Get/Scan Changes.

Page through newest-first record-version entries. Enable both keepAllVersions and keepUpdateHistoryIndex and continue with nextCursor.

See Get/Scan Update History.

Read chronological synchronization events or use executeFlow for a current live view. Live views and finite history have different delivery and paging semantics.

See Get/Scan Updates.

See replication input validation for source-version ordering and envelope requirements.

Use a transaction when reads determine the writes, or when a record must be changed repeatedly. Reads see prior staged writes; commit can report a conflict. Staged versions are provisional, and uncertain commits require the original handle.

See Serializable transactions for an example, savepoints, retry policy, capabilities and recovery. These are distinct from snapshot reads.