Custom Databases Overview
The Boltic Tables SDK provides comprehensive support for managing multiple databases within your workspace. By default, all operations use your default Boltic Cloud database. You can create custom databases and switch between them using the database context management features.
import { createClient } from "@boltic/sdk";
const client = createClient("your-api-key");
// All database operations
const operations = client.databases;
What are Custom Databases?
Custom databases allow you to organize your data across multiple independent database instances. Each database is completely separate and can contain its own tables, records, columns, and indexes. This enables:
- Data Isolation: Separate databases for different projects, environments, or tenants
- Organization: Group related data in dedicated databases
- Flexibility: Switch between databases without changing your code structure
Default Database Behavior
If you never call useDatabase(), all operations automatically target your account's default Boltic Cloud database.
Core Capabilities
The SDK provides comprehensive database management through the client.databases interface:
Database Management Operations
| Operation | Method | Description |
|---|---|---|
| Create Database | create() | Create a new database |
| List Databases | findAll() | List all active databases with filtering |
| Get Database | findOne(), getDefault() | Retrieve database details by slug or get default |
| Update Database | update() | Update database display name |
| Delete Database | delete() | Initiate database deletion (async) |
| List Database Jobs | listJobs() | List deletion and other database jobs |
| Poll Delete Status | pollDeleteStatus() | Check deletion job completion status |
| Switch Database Context | useDatabase(), getCurrentDatabase() | Switch context and inspect current database |
Database Context
When you switch to a custom database using useDatabase(), all subsequent operations on tables, records, columns, indexes, and sql automatically target that database. This provides a way to work with multiple databases without explicitly passing database identifiers to each operation.
Quick Start Example
import { createClient } from "@boltic/sdk";
const client = createClient("your-api-key");
// 1. List all databases
const { data: databases, error } = await client.databases.findAll();
if (error) {
console.error("Failed to list databases:", error.message);
} else {
console.log(`Found ${databases.length} databases`);
}
// 2. Create a new database
const { data: newDb, error: createError } = await client.databases.create({
db_name: "My Custom Database",
db_internal_name: "my_custom_db",
});
if (createError) {
console.error("Failed to create database:", createError.message);
} else {
console.log("Database created:", newDb.db_internal_name);
// 3. Switch to the new database
await client.useDatabase(newDb.db_internal_name);
// 4. Create a table in the custom database
const { data: table } = await client.tables.create({
name: "my_table",
fields: [
{ name: "title", type: "text", is_nullable: false },
{ name: "description", type: "long-text", is_nullable: true },
],
});
console.log("Table created in custom database:", table.id);
// 5. Switch back to default database
await client.useDatabase();
}
Next Steps
- Create your first database - Start with basic database creation
- List and manage databases - Discover and filter your databases
- Switch database context - Learn how to work with multiple databases