Developer guide · alpha · nine steps

Build for one person. Then many.

LastDB is in alpha. It runs as one local daemon. Your apps send HTTP requests to it over a Unix socket. Build your app for one person first: steps 1 to 7. Then let people share a database (step 8) and publish the app (step 9).

Install first if you do not have a node yet. The install by hand and the node checks are in the Docs.

01 · What LastDB is

Steps 1 to 7 are an app for one person. No account and no network.

Records, found by key.

LastDB is a key-value database. You find a record by its key. There is no read that returns everything, except the key listing in step 5.

Daemon
The background process, lastdbd. It holds the data on this machine.
Socket
The file ~/.lastdb/data/folddb.sock. Your requests go to this file. The name is the real file name; it is not a product name.
Schema
A named record type. It lists its fields and its keys.
Record
One stored value of one schema. It sits at one key.
Primary key
The key that finds a record. It has a hash, the first part of the key. A schema can also use a range, the second part. This guide uses a hash only.
Alternate key
A second named key that finds the same record. You give its value when you write the record.
Query
A read. It must name a key. A read with no key is refused.
02 · Check the node

Check the node.

Run these two requests. Both use the socket.

Health and status
curl -s --unix-socket ~/.lastdb/data/folddb.sock http://localhost/health
curl -s --unix-socket ~/.lastdb/data/folddb.sock http://localhost/api/status

/health returns {"status":"ok", ...} with the API version and the node instance id. /api/status returns a summary of the running node.

03 · Declare a schema

Declare a schema.

A schema must exist before you write to it. This example declares a note. Each note has an id, a tag, and a body. The id is the primary key. The tag is an alternate key, so you can find notes by tag.

POST /api/schemas/declare
curl -s --unix-socket ~/.lastdb/data/folddb.sock \
  -X POST http://localhost/api/schemas/declare \
  -H "Content-Type: application/json" \
  -d '{
    "namespace": "notes",
    "schema": {
      "name": "note",
      "schema_type": "Hash",
      "record_keys": {
        "primary": { "kind": "hash" },
        "alternates": { "by_tag": { "kind": "hash" } }
      },
      "fields": ["id", "tag", "body"],
      "field_types": { "id": "String", "tag": "String", "body": "String" }
    }
  }'

namespace is your app name. It cannot contain a slash. The schema becomes notes/note. Use that name in the next steps.

Declaring the same shape again is safe. The reply shows resolution as reuse when the schema already exists, and register when it is new. Changing a field or a key of an installed schema is refused. Declare a new schema name instead.

04 · Write and read

Write a record, read it back.

POST /api/mutationwrite
curl -s --unix-socket ~/.lastdb/data/folddb.sock \
  -X POST http://localhost/api/mutation \
  -H "Content-Type: application/json" \
  -d '{
    "type": "mutation",
    "schema": "notes/note",
    "record": { "id": "n1", "tag": "work", "body": "Ship the page" },
    "key_value": { "hash": "n1", "range": null },
    "alternates": { "by_tag": { "hash": "work", "range": null } },
    "mutation_type": "create",
    "expected": { "type": "absent" }
  }'

key_value is the primary key. alternates gives one value for each named alternate key. Every field in record must be declared in step 3. expected set to absent means the key must not exist yet. The reply has ok: true and success: true.

POST /api/queryread by primary key
curl -s --unix-socket ~/.lastdb/data/folddb.sock \
  -X POST http://localhost/api/query \
  -H "Content-Type: application/json" \
  -d '{"schema_name":"notes/note","filter":{"HashKey":"n1"}}'

HashKey selects one record by its primary hash. The reply has ok: true and a results list. Each result has a key and its fields. A schema with a range uses HashRangeKey with both hash and range.

POST /api/queryread by alternate key
curl -s --unix-socket ~/.lastdb/data/folddb.sock \
  -X POST http://localhost/api/query \
  -H "Content-Type: application/json" \
  -d '{"schema_name":"notes/note","filter":{"HashKey":"work"},"key_name":"by_tag"}'

Add key_name to read by an alternate key. The HashKey value is the alternate key value, here the tag.

05 · List keys

List the keys of a schema.

This is the one whole-schema read. It lists every key of the schema. It returns one page at a time, and it does not return the field values. Use it to find keys, then read each record by key in step 4.

GET /api/list
curl -s --unix-socket ~/.lastdb/data/folddb.sock \
  "http://localhost/api/list?schema=notes/note&limit=2"

limit sets the page size. The default is 100. The maximum is 1000. The reply has list.keys, list.has_more, and list.next_cursor.

Next page
curl -s --unix-socket ~/.lastdb/data/folddb.sock \
  "http://localhost/api/list?schema=notes/note&limit=2&cursor=CURSOR"

Replace CURSOR with the next_cursor value from the last reply, percent-encoded. Stop when has_more is false. Add &hash=n1 to list only the keys under one hash.

06 · Command line

The same reads from the command line.

The lastdb command runs the same reads. Add --json for the raw reply.

lastdb
lastdb status
lastdb get notes/note --key-hash n1
lastdb get-keys notes/note --limit 2
lastdb get-keys notes/note --key-hash work --key-name by_tag

get reads one record by key. get-keys lists keys, as step 5 does. --key-name needs --key-hash. Writes go through the socket request in step 4.

07 · Errors

Errors name the problem.

A failed request returns a 4xx or 5xx status. A 400 from this socket returns a JSON body that names the problem. This example comes from a read with no key:

400 Bad Request
{
  "ok": false,
  "kind": "full_schema_scan_not_allowed",
  "error": "product apps are keyed-access only; unfiltered schema queries are not supported",
  "message": "full_schema_scan_not_allowed: unfiltered query on product schema 'note' is not supported; add a keyed filter using the structured remediation",
  "schema_name": "note",
  "schema_id": "notes/note",
  "remediation": { "action": "add_key_filter", "request_key": "filter", "...": "trimmed" }
}

kind is the error code. Fix the request and send it again. A malformed mutation or query body returns kind, error, and sometimes key and try, with a corrected example.

08 · Share a database

Steps 8 and 9 are for many people. Shown with the lastdb command line.

Share a database.

A node holds several named databases. One person, the publisher, shares a whole database with other people. Data for a different audience goes in a different database.

1. The recipient exports a contact file
lastdb share contact --out ben.contact

The recipient sends this file to the publisher. Each side also gives the other their public key over a channel they already trust.

2. The publisher creates a database and invites
lastdb db create family-notes
lastdb --db family-notes share invite \
  --recipient ben.contact --recipient-key "$BEN_KEY" \
  --out ben.invite

The invitation is encrypted for that one recipient. The read permission in it lasts 24 hours unless you pass --expires-in-hours.

3. The recipient accepts
lastdb share accept --publisher "$ANA_KEY" \
  --name family-notes ben.invite

The database appears on the recipient’s node and stays in step with the publisher’s.

Who can write

Everyone invited can read the whole database. The publisher grants writing with lastdb share contributors grant and removes it with lastdb share contributors revoke.

A change from another person goes, encrypted, to the publisher’s node. That node checks the change against the sharing rules and the schema. It publishes the changes that pass and drops the ones that fail. Your app does not enforce this, so a modified copy of your app cannot get around it.

The cloud between the nodes is a central service. It stores and passes along encrypted bytes that it cannot read. It is not a peer-to-peer network.

09 · Publish your app

Publish your app.

An app has no server, so there is nothing to deploy. A release is a signed entry in the App Registry.

Publish and install
lastdb app publish --manifest manifest.json
lastdb app install your-app

The manifest names the app, its schemas, and the commit to install. Each person installs the app by name, and it runs on their own Mac.

Publishing needs a paid Exemem subscription. Exemem is the cloud service that LastDB uses for backup and sharing. People who use a published app pay nothing to use it. Building and running an app on your own Mac needs no subscription.

Next

Where to go from here.

The interactive guide shows the layers, their parts, and their connections.

Explore the system →   Full catalog of apps →   Install and node health: Docs →