Skip to Content
PlatformDatabases

Databases

Databases give StackMachine apps durable application state for records, user data, queues, and product workflows. Create a database for an app, store the returned credentials securely, and rotate credentials whenever access changes.

Features

Per-app databases

Create databases against an app ID and list the databases attached to that app. The SDK returns host, port, username, and explorer URLs where available.

Engine selection

The JavaScript SDK accepts POSTGRES, MYSQL, or SQLITE as database engines. Use the engine that matches your application runtime and migration workflow.

Credentials returned once

Creation and rotation return a plaintext password once. Store it as an environment variable or secret immediately.

Credential rotation

Rotate database credentials from the SDK when replacing secrets or handing ownership to another environment.

Common workflow

  1. Create the database with the app ID, engine, and name.
  2. Store the returned password in the app environment.
  3. List databases to verify the attachment.
  4. Rotate credentials when access should change.

SDK examples

Create, list, and rotate credentials

Create a Postgres database for an app, inspect the connection fields, list databases, and rotate credentials.

databases.js
1
const { database, password } = await client.apps.databases.create({
2
  app: "da_XYZ",
3
  dbEngine: "POSTGRES",
4
  name: "primary",
5
});
6
 
7
console.log(database.host, database.port, database.username);
8
console.log("Initial password, returned once:", password);
9
 
10
const databases = await client.apps.databases
11
  .list({ app: "da_XYZ", limit: 10 })
12
  .autoPagingToArray({ limit: 25 });
13
console.log(databases.map((item) => item.name));
14
 
15
const rotated = await client.apps.databases.rotateCredentials(database.id);
16
console.log("Rotated password, returned once:", rotated.password);

Source: stackmachine/sdks  JavaScript examples.