Skip to content

Database — Features

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.

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]
)
MethodReturnsUse when
sdk.db.query(sql, params){ results: T[] }SELECT, INSERT, UPDATE, DELETE
sdk.db.queryOne(sql, params)T | nullFetch a single row
sdk.db.exec(sql)voidDDL statements (CREATE TABLE, etc.)
sdk.db.batch(statements)results[]Multiple statements in one round-trip

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] },
])
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 } | null
// 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']
)

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]
)

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.

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.

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.