Databases

services.db() opens a managed SQLite or PostgreSQL handle.

JavaScript
const db = services.db({
  driver: "postgres",
  connection: secrets.POSTGRES_URL
});
const customer = await db.query({
  text: "select id, name from customers where id = $1",
  values: [context.payload.customerId]
}, { name: "load-customer" });
return customer.rows[0] ?? null;

Use parameterized queries rather than interpolating data into SQL. Managed writes and transactions carry durable operation identity and bounded results. Return plain data, never a database client.

The released database service supports SQLite and PostgreSQL. NoSQL and document databases are not currently built in; wrap another database API in a local module or managed HTTP call.

Open the correct database

JavaScript
const db = services.db({
  driver: "postgres",
  connection: secrets.POSTGRES_URL
});

For SQLite, use a project data file that is separate from WOML's runtime-state database. Never run application queries against workflow-history.sqlite or another engine-owned state file.

Query safely

JavaScript
const result = await db.query({
  text: "select id, name from customers where id = $1",
  values: [context.payload.customerId]
}, { name: "load-customer" });

return { customer: result.rows[0] ?? null };

SQLite uses ? placeholders and PostgreSQL uses $1, $2, and so on. Always pass untrusted values separately instead of interpolating SQL strings.

Write and transact

Use insert, update, delete, execute, or transaction for mutations. Update and delete helpers require a non-empty where condition to prevent accidental full-table writes. An intentional bulk operation should use explicit reviewed SQL.

Transactions contain 1–100 managed operations on one connection and commit only when every operation succeeds. Return plain rows or bounded mutation metadata, never the database handle.

Use a database for records and queries. Do not use durable state as a replacement for customer tables, searchable collections, or relational transactions.