Database
Aerostack provides a managed SQL database (SQLite-compatible), accessible from your server-side SDK. Every project gets its own isolated database with full SQL support, schema migrations, and intelligent connection routing.
Quick start
import { sdk } from '@aerostack/sdk'
// Single row query
const user = await sdk.db.queryOne(
'SELECT * FROM users WHERE id = ?',
[userId]
)
// Multiple rows
const posts = await sdk.db.query(
'SELECT * FROM posts WHERE user_id = ? ORDER BY created_at DESC',
[userId]
)
// Insert
await sdk.db.query(
'INSERT INTO posts (id, user_id, title, body) VALUES (?, ?, ?, ?)',
[newId, userId, title, body]
)Query methods
| Method | Returns | Use when |
|---|---|---|
sdk.db.query(sql, params) | { results: T[] } | SELECT, INSERT, UPDATE, DELETE |
sdk.db.queryOne(sql, params) | T | null | Fetch a single row |
sdk.db.exec(sql) | void | DDL statements (CREATE TABLE, etc.) |
sdk.db.batch(statements) | results[] | Multiple statements in one round-trip |
Batch operations
Run multiple statements atomically:
const results = await sdk.db.batch([
{ sql: 'INSERT INTO orders (id, user_id) VALUES (?, ?)', params: [orderId, userId] },
{ sql: 'UPDATE inventory SET stock = stock - 1 WHERE product_id = ?', params: [productId] },
{ sql: 'INSERT INTO audit_log (action, user_id) VALUES (?, ?)', params: ['order_created', userId] },
])Batch operations run in a transaction — if any statement fails, all are rolled back.
TypeScript types
const user = await sdk.db.queryOne<{
id: string
email: string
name: string
created_at: string
}>('SELECT * FROM users WHERE id = ?', [userId])
// user is typed: { id: string, email: string, name: string, created_at: string } | nullSchema introspection
// List all tables in your database
const tables = await sdk.db.query(
"SELECT name FROM sqlite_master WHERE type='table'"
)
// Describe a table's columns
const columns = await sdk.db.query(
'PRAGMA table_info(?)',
['users']
)Use Cases
Product catalog CRUD
Store and query your product catalog with full SQL flexibility. Use parameterized queries for filtering by category, price range, or availability, and batch operations for bulk inventory updates.
// Find products matching filters
const products = await sdk.db.query<Product>(
`SELECT * FROM products
WHERE category = ? AND price BETWEEN ? AND ? AND in_stock = 1
ORDER BY created_at DESC LIMIT 20`,
[category, minPrice, maxPrice]
)Multi-tenant data isolation
Each Aerostack project gets its own isolated database, so tenant data is physically separated. For applications that need even stronger isolation, dedicated databases ensure no tenant can ever query another tenant’s data, simplifying compliance with data residency requirements.
Analytics queries with batch reads
Run multiple analytics queries in a single round-trip using batch operations. Aggregate metrics like daily active users, revenue totals, and conversion rates in one call instead of making separate requests for each dashboard widget.
Audit logging
Use batch operations to atomically write business data alongside an audit trail. Every insert, update, or delete can be paired with an audit log entry in a single transaction, ensuring your compliance records are always consistent with the source data.
Next steps
- Querying — full query API with examples
- Schema & Migrations — managing your database schema
- Batch Operations — transactions and bulk writes