Menu

SDK modules

Besides the globals in the Handler API, MicroHost ships four optional modules. They are reserved import specifiers served by the host, written in plain JavaScript, versioned with the SDK API version (currently 1), and loaded lazily: a handler that imports none of them does no extra work.

Module (import) Manifest sdk name Purpose Needs Engines
microhost/sql sql The sql tagged template for composable, parameterized SQL. nothing by itself Wasm, native, Linux
microhost/db (alias db) db Object rows, table objects, paging, all/one/run/tx, id(), now(). the database grant Wasm, native, Linux
microhost/auth auth hashPassword, verifyPassword (Argon2id). no database grant Wasm, native, Linux
microhost/session session Cookie sessions stored in your database. the database grant, a site_sessions table all engines (see below)

Reference pages: Database SDK for sql and db, Auth and sessions for auth and session.

Status: session on native and Linux. Implemented once in the shared SDK layer for every engine. Verified end to end on Wasm (dev VM, 2026-10-25); native and Linux load the same module and dispatch, but a full cycle against real SQLite is not yet tested there. microhost/auth, microhost/sql and microhost/db work on all three engines.

Importing

import { sql } from "microhost/sql";
import { all, one, run, tx, id, now, tasks, tables } from "microhost/db";   // same as: from "db"
import { hashPassword, verifyPassword } from "microhost/auth";
import { create, get, destroy, destroyAll } from "microhost/session";

Requesting modules in the manifest

List the modules your release uses in the manifest's sdk array:

{ "schemaVersion": 1, "sdk": ["db", "auth", "session"], "permissionsRequested": { "database": true } }

or, in microhost.config.js, defineSite({ sdk: ["db"], ... }).

Rules (checked at deploy; a bad list rejects the manifest):

The per-site module switch

An administrator can disable a module for a site without redeploying:

The switch is a developer convenience, not authorization. It never grants anything. In particular, ctx.db is governed only by the database grant: disabling db does not remove raw ctx.db, and enabling db does not give database access. Every SDK database call goes through the same broker checks as ctx.db.

Versioning

The SDK API version (SDK_API_VERSION = 1) is pinned in each release record. Module behaviour for existing releases does not change when the platform upgrades. A behaviour change requires a new SDK version and new release pinning. Table exports of microhost/db come from the release's sealed schema snapshot (see Migrations); a release created before snapshots existed gets none until it is redeployed, but raw ctx.db keeps working for it.