MyloDB Docs

Build with MyloDB

Go from an empty account to a live, offline-ready app, then reach for the HTTP API whenever you need it.

Quickstart

Sign in to the console with your email or Google account and create an app. Its id becomes part of every URL, and the first admin key is shown once, so store it somewhere safe.

You can do the same from a terminal with the server's admin key or a console session token:

bash
curl -X POST __ORIGIN__/v1/admin/apps \
  -H 'x-mylodb-admin-key: $MYLODB_ADMIN_KEY' \
  -H 'content-type: application/json' \
  -d '{"id":"notes","name":"Notes"}'

The response carries admin_key.token, an mdb_app_… key that only works on this app. Use it from your backend and CI, never in a browser or an iOS binary.

TypeScript and React

The web SDK runs the shared Rust client engine as WebAssembly, keeps a copy of your data in IndexedDB, and never throws: every fallible call returns { ok: true, data } or { ok: false, error }.

tsx
import { createMylo } from "@mylodb/client/react";
import { id } from "@mylodb/client";

export const db = createMylo({ appId: "notes", apiURI: "__ORIGIN__" });

// await before the first render so cached data paints without a skeleton
await db.ready();

function Notes() {
  const { isLoading, data, error } = db.useQuery({
    notes: { $: { order: { createdAt: "desc" }, limit: 50 } },
  });
  if (isLoading) return <NotesSkeleton />;
  if (error) return <p>{error.message}</p>;
  return data.notes.map((note) => <Note key={note.id} note={note} />);
}

const saved = await db.transact(
  db.tx.notes[id()].update({ title: "Ship it", createdAt: Date.now() }),
);
if (!saved.ok) console.warn(saved.error.code); // already rolled back locally

isLoading is only true before the server has ever answered and nothing is cached, so it's the one moment to show a skeleton. Writes made offline are kept and replayed after reconnecting.

Swift

MyloDBKit hosts the same engine through UniFFI. MyloStore is an @Observable main-actor store, and every call returns Result<T, MyloError>.

swift
let store = MyloStore(configuration: .init(
    appID: "notes",
    baseURL: URL(string: "__ORIGIN__")!,
    schemaJSON: bundledSchema
))

// loads this user's snapshot synchronously, then connects
store.open(userID: session.userID, token: session.token)

let notes = store.liveQuery(#"{"notes":{"$":{"order":{"createdAt":"desc"}}}}"#)

let write = store.transact([
    .upsert("notes", id: MyloID.make(), attrs: ["title": "Ship it"])
])

Add the package by path, or vendor it with sdks/swift/vendor.sh for builds that don't have the repo next to them.

Schema and rules

A schema names your entities, their attributes and the links between them. Rules decide who can view, create, update and delete each entity, and can hide single fields. Push both together:

bash
curl -X PUT __ORIGIN__/v1/apps/notes/schema \
  -H 'x-mylodb-admin-key: $APP_KEY' \
  -H 'content-type: application/json' \
  -d '{
    "schema": {
      "entities": {
        "notes": { "attrs": {
          "title": { "type": "string" },
          "ownerId": { "type": "string" },
          "createdAt": { "type": "number" }
        } }
      },
      "links": {}
    },
    "rules": {
      "notes": {
        "allow": {
          "view": "auth.id == data.ownerId",
          "create": "auth.id == newData.ownerId",
          "update": "auth.id == data.ownerId",
          "delete": "auth.id == data.ownerId"
        }
      },
      "$users": {
        "allow": { "view": "auth.id != null" },
        "fields": { "email": "auth.id == data.id" }
      }
    }
  }'

Rules can read auth, the row as data, the incoming row as newData, other rows with data.ref("owner.id"), and helpers like startsWith. Admin keys bypass rules; everyone else is checked on every query, delta and write.

Queries, search and cursors

A query is a JSON tree: each key is an entity, $ holds its filters, and nested keys follow links.

bash
curl -X POST __ORIGIN__/v1/apps/notes/query \
  -H 'authorization: Bearer $USER_TOKEN' \
  -H 'content-type: application/json' \
  -d '{
    "notes": {
      "$": {
        "where": { "title": { "$ilike": "%launch%" }, "createdAt": { "$gte": 1735689600000 } },
        "order": { "createdAt": "desc" },
        "first": 20
      },
      "owner": {}
    }
  }'
  • Filters: equality, $in, $ne, $gt, $gte, $lt, $lte, $isNull, and / or, and dotted paths into linked rows such as "owner.email".
  • Search: $like (case-sensitive, % and _ wildcards), $ilike (case-insensitive) and $contains.
  • Cursors: set first or last, then pass the previous page's page_info.notes.end_cursor as after (or start_cursor as before). The response's page_info also says whether more rows exist.
  • Offsets: limit and offset still work for simple lists.

Transactions

Every write is an atomic list of upsert, delete, link and unlink operations. Send a client_tx_id to make retries safe: the same identity resending it gets the original commit back.

bash
curl -X POST __ORIGIN__/v1/apps/notes/transact \
  -H 'authorization: Bearer $USER_TOKEN' \
  -H 'content-type: application/json' \
  -d '{
    "client_tx_id": "7d0c6c1e-2f4b-4c1f-9a51-3a9e4b1d2c10",
    "ops": [
      { "op": "upsert", "entity": "notes", "id": "n1", "attrs": { "title": "Ship it", "ownerId": "u1" } },
      { "op": "link", "entity": "notes", "id": "n1", "label": "owner", "target_id": "u1" }
    ]
  }'

Catch up after being offline with GET /v1/apps/notes/deltas?since_seq=120, or open /v1/apps/notes/ws for live updates; the SDKs do both for you.

Auth

Each app has its own users in $users. Send a six-digit code by email, verify it, and use the returned token as a bearer token.

bash
curl -X POST __ORIGIN__/v1/apps/notes/auth/send-magic-code \
  -H 'content-type: application/json' -d '{"email":"[email protected]"}'

curl -X POST __ORIGIN__/v1/apps/notes/auth/verify-magic-code \
  -H 'content-type: application/json' -d '{"email":"[email protected]","code":"123456"}'

Tokens are revocable sessions: POST …/auth/verify-token checks one and POST …/auth/sign-out revokes it.

Files and images

Uploads become $files rows guarded by your $files rules. Images get their width, height and a BlurHash placeholder automatically, and every URL the server hands out is signed for about a day.

bash
curl -X PUT __ORIGIN__/v1/apps/notes/files/u1/cover.png \
  -H 'authorization: Bearer $USER_TOKEN' \
  -H 'content-type: image/png' \
  --data-binary @cover.png

# resize and convert on the fly
curl '__ORIGIN__/v1/apps/notes/files/u1/cover.png?w=400&fmt=webp&token=$USER_TOKEN' -o cover.webp

Backups and buckets

Link your own S3 or Cloudflare R2 bucket to store files there and take nightly gzipped SQLite snapshots. You can also take a snapshot right now:

bash
curl -X PUT __ORIGIN__/v1/apps/notes/storage/bucket \
  -H 'x-mylodb-admin-key: $APP_KEY' -H 'content-type: application/json' \
  -d '{"endpoint":"https://ACCOUNT.r2.cloudflarestorage.com","region":"auto","bucket":"notes-data",
       "access_key_id":"…","secret_access_key":"…","use_for_files":true,"nightly_backups":true}'

curl -X POST __ORIGIN__/v1/apps/notes/backups/run -H 'x-mylodb-admin-key: $APP_KEY'
curl __ORIGIN__/v1/apps/notes/backups -H 'x-mylodb-admin-key: $APP_KEY'

Collaborators

Invite teammates from the app's Team tab or the API. Someone without an account yet gets a pending invite that turns into access the first time they sign in with that email.

RoleCan do
OwnerEverything, including deleting the app.
AdminManage settings, schema and rules, keys, buckets, backups and collaborators.
EditorCreate, update and delete rows and files.
ViewerBrowse data, analytics, usage and backups.
bash
curl -X POST __ORIGIN__/v1/admin/apps/notes/members \
  -H 'authorization: Bearer $CONSOLE_TOKEN' -H 'content-type: application/json' \
  -d '{"email":"[email protected]","role":"editor"}'

Limits and quotas

Each app can have a request rate limit, a row limit, a storage limit and a live-connection limit. Going over answers with a clear error instead of slowing everyone else down:

  • 429 rate_limited with a retry-after header when requests outpace the rate limit.
  • 413 quota_exceeded when new rows or uploads won't fit. Updates and deletes always go through, so you can clean up.
  • 429 ws_quota_exceeded when the app already has its maximum number of live sockets.

See current usage in the app's Team tab or with GET /v1/admin/apps/notes/usage. Only the server's operator can change limits.

HTTP API reference

Admin routes take the server's admin key or an app key in x-mylodb-admin-key, or a console session as a bearer token. App routes take an app user's token and apply your rules.

RouteWhat it does
POST /v1/admin/appsCreate an app and return its first admin key once.
GET /v1/admin/apps/{app}Rows per entity, live connections, users and storage.
GET /v1/admin/apps/{app}/usageUsage against the app's limits.
GET/POST /v1/admin/apps/{app}/membersList or invite collaborators.
GET/POST /v1/admin/apps/{app}/keysList or create per-app admin keys.
GET/PUT /v1/apps/{app}/schemaRead the schema, or push schema and rules.
POST /v1/apps/{app}/queryRun one query.
POST /v1/apps/{app}/transactCommit one atomic transaction.
GET /v1/apps/{app}/deltasChanges since a sequence number.
GET /v1/apps/{app}/wsLive sync over WebSocket.
POST /v1/apps/{app}/auth/…Send and verify magic codes, verify tokens, sign out.
PUT /v1/apps/{app}/files/{path}Upload a file or image.
GET /v1/apps/{app}/files/{path}Download, resize or convert a file.
POST /v1/apps/{app}/backups/runTake a snapshot now.

Errors always come back as { "code": "…", "message": "…" }, where the message says what went wrong and what to try next.

No sections mention . Try a shorter word, like "rules" or "upload".