RaisFastRaisFast
Plugins

Host API

Complete SDK function reference for all four runtimes — database, HTTP, VFS, KV store, config, events.

The Host API is the interface between plugins and RaisFast. All functions are permission-gated — access is denied unless declared in [permissions].

Database

Raw SQL

FunctionDescription
dbQuery(sql, params?)SELECT query, returns array of objects
dbExec(sql, params?)INSERT / UPDATE / DELETE, returns { rows_affected }
dbBegin()Begin transaction
dbCommit()Commit transaction
dbRollback()Rollback transaction
const rows = dbQuery("SELECT * FROM products WHERE price > ?", [100]);
const result = dbExec("UPDATE products SET stock = stock - 1 WHERE id = ?", [id]);

Note: dbQuery returns integer columns as null. Use CAST(col AS TEXT) and then parseInt().

High-Level DB API

FunctionReturnsDescription
dbInsert(table, data, options?){ rows_affected }Insert a row
dbFetchOne(table, where?, options?)data or nullFetch single row
dbFetchAll(table, where?, options?){ data, total }Fetch multiple rows
dbUpdate(table, data, where?, options?){ rows_affected }Update rows
dbDelete(table, where?, options?){ rows_affected }Delete rows
dbCount(table, where?, options?){ count }Count rows
dbIncrement(table, cols, where?, options?){ rows_affected }Atomic increment/decrement
dbSum(table, column, where?, options?){ sum }SUM aggregate
dbGroupBy(table, options?){ data, total }GROUP BY with aggregates
dbInsert("orders", { title: "New Deal", amount: 5000 });

const deal = dbFetchOne("orders", { id: "abc123" });

const { data } = dbFetchAll("orders",
  { status: "active" },
  { order_by: "amount DESC", limit: 10, offset: 0 }
);

dbUpdate("orders", { status: "closed" }, { id: "abc123" });

dbDelete("orders", { status: "cancelled" });

const { count } = dbCount("orders", { status: "active" });

dbIncrement("orders", { view_count: 1 }, { id: "abc123" });

const { sum } = dbSum("orders", "amount", { status: "closed" });

const { data } = dbGroupBy("orders", {
  group_by: "status",
  count: true,
  sum: "amount"
});

Where Formats

The where parameter accepts two formats:

Object (auto-generates WHERE col = ? AND ...):

{ status: "active", category: "electronics" }

Array (parameterized SQL):

["amount > ? AND status = ?", [1000, "active"]]

Empty/null means no WHERE clause.

Options

KeyDescription
order_bySort: "col ASC" or "col1 ASC, col2 DESC"
limitMax rows to return
offsetNumber of rows to skip
tenant"some_id" (explicit), false (disabled), omitted (auto)

SQL Placeholder

Use dbPh(idx) to get the correct placeholder for the current database:

  • SQLite / MySQL: ?
  • PostgreSQL: $1, $2, ...
const ph = dbPh(1); // "?" on SQLite, "$1" on PostgreSQL

Transactions

dbBegin();
try {
  dbExec("INSERT INTO orders ...");
  dbExec("UPDATE products SET stock = stock - 1 ...");
  dbCommit();
} catch (e) {
  dbRollback();
}

HTTP

FunctionReturnsDescription
httpGet(url)string or nullHTTP GET, raw response
httpGetJson(url)object or nullHTTP GET, parsed JSON
httpPost(url, body)string or nullHTTP POST, raw response
httpPostJson(url, body)object or nullHTTP POST, parsed JSON

Requires http permission. 10-second timeout, 1 MB max response body.

const data = httpGetJson("https://api.example.com/v1/products");
const result = httpPostJson("https://api.example.com/webhook", { event: "test" });

Virtual Filesystem (VFS)

FunctionReturnsDescription
vfsRead(path)string or nullRead file content
vfsWrite(path, content)boolWrite file (auto-creates dirs)
vfsDelete(path)boolDelete file
vfsExists(path)boolCheck if file exists
vfsList(path)string[]List directory
vfsStat(path)object or nullFile metadata

Requires filesystem permission. Each plugin has an isolated sandbox at {VFS_ROOT}/{plugin_id}/. Path traversal (..) is blocked.

vfsWrite("/reports/daily.json", JSON.stringify(report));
const data = JSON.parse(vfsRead("/reports/daily.json"));
const exists = vfsExists("/reports/daily.json");
const files = vfsList("/reports");
const stat = vfsStat("/reports/daily.json");
// { size: 1024, is_dir: false, modified: 1700000000 }

Quotas: single file max PLUGIN_VFS_MAX_FILE_SIZE (default 1 MB), total max PLUGIN_VFS_MAX_TOTAL_SIZE (default 10 MB).

KV Store

FunctionReturnsDescription
storeGet(key)string or nullRead value
storeSet(key, value)boolWrite value (upsert)

Data is scoped by plugin ID — plugins cannot access each other's data.

storeSet("last_sync", "2026-01-01");
const val = storeGet("last_sync");

Config

FunctionReturnsDescription
configGet(key)string or nullRead config value

Requires config permission. Available keys: app.host, app.port, app.env, app.base_url, jwt.access_expires, jwt.refresh_expires, upload.dir, upload.max_size, plugin.max_memory_mb, plugin.default_timeout_ms.

Content Query

FunctionReturnsDescription
getPost(slug)object or nullGet post by slug

Requires read:posts database permission.

Utility

FunctionReturnsDescription
ok(data)anyReturn success data
fail(status, msg)error objectReturn HTTP error
extractJson(input, field?)anyParse JSON and extract field (supports dot path: "params.id")
logInfo(msg)Log at info level
logWarn(msg)Log at warn level
logError(msg)Log at error level
newId()stringGenerate UUID v7
eventEmit(type, data)Emit custom event

Runtime Function Name Mapping

JS and Lua use camelCase. Rhai uses snake_case. WASM uses kebab-case in WIT.

JS / LuaRhaiWASM (WIT)
dbQuerydb_querydb-query
dbExecdb_executedb-execute
dbBegindb_begindb-begin
dbCommitdb_commitdb-commit
dbRollbackdb_rollbackdb-rollback
dbInsertdb_insert
dbFetchOnedb_fetch_one
dbFetchAlldb_fetch_all
dbUpdatedb_update
dbDeletedb_delete
dbCountdb_count
dbIncrementdb_increment
dbSumdb_sum
dbGroupBydb_group_by
httpGethttp_gethttp-get
httpPosthttp_posthttp-post
getConfigget_configget-config
storeGet / getDataget_dataget-data
storeSet / setDataset_dataset-data
getPostget_postget-post
vfsReadvfs_readvfs-read
vfsWritevfs_writevfs-write
vfsDeletevfs_deletevfs-delete
vfsExistsvfs_existsvfs-exists
vfsListvfs_listvfs-list
vfsStatvfs_statvfs-stat
emitEventemit_eventemit-event
newIdnew_id
logloglog
dbPhdb_ph

Runtime-Specific Functions

Rhai Only

FunctionDescription
parse_json(str)Parse JSON to Rhai value
to_json(val)Convert Rhai value to JSON
to_upper(str)Uppercase
to_lower(str)Lowercase
replace(str, from, to)String replace
remove(map, key)Remove key from map

Lua Only

FunctionDescription
Host.jsonEncode(val)Encode Lua value to JSON
Host.jsonDecode(str)Decode JSON to Lua value

Lua's sandbox has no native JSON support, so these are provided as host functions.

WASM Limitations

The WIT interface currently provides only raw SQL (db-query, db-execute). High-level DB API (dbInsert, dbFetchOne, etc.), newId, and dbPh are not yet available in WASM.

On this page