Documentation
Everything you need to build and scale your application with Scarlet.
Quick Start
View on npm$ npm install @scarletdb/sdk
import { Scarlet } from '@scarletdb/sdk';
const db = new Scarlet({ apiKey: 'sk_live_...' });SDK Modules
Data API
Query and manipulate your database with a fluent TypeScript API.
const users = await db.from('users')
.select()
.where({ active: true })
.limit(10);Storage
Upload, download, and manage files in cloud storage buckets.
await db.storage.upload('avatars', file);
const url = db.storage.getPublicUrl('avatars', 'pic.png');Send transactional emails with custom domains and templates.
await db.email.send({
from: 'hello@myapp.com',
to: 'user@email.com',
subject: 'Welcome!',
html: '<h1>Hello!</h1>'
});AI Queries
Query your database using natural language, powered by AI.
const result = await db.ai.query(
'Show me users who signed up last week'
);
console.log(result.sql); // Generated SQL
console.log(result.rows); // ResultsRaw SQL
Execute parameterized SQL queries directly when you need full control.
const result = await db.sql.query(
'SELECT * FROM users WHERE id = $1',
[userId]
);Configuration
const db = new Scarlet({
// Required: Your project API key
apiKey: 'sk_live_...',
// Optional: Custom API URL (defaults to production)
baseUrl: 'https://api.scarletdb.space',
// Optional: Request timeout in ms (default: 30000)
timeout: 30000,
});Error Handling
import { Scarlet, ScarletError } from '@scarletdb/sdk';
try {
await db.from('users').insert({ email: 'test' });
} catch (error) {
if (error instanceof ScarletError) {
console.error(error.message); // Error message
console.error(error.status); // HTTP status code
console.error(error.code); // Error code
}
}