Create Database
Create a new database using client.databases.create(). If you omit db_internal_name, Boltic automatically derives one from the display name. The resource_id defaults to "boltic" for managed databases. To create a database in a custom resource, use a connector ID starting with btb- from the connectors list.
Method Signature
client.databases.create(request: DatabaseCreateRequest): Promise<BolticSuccessResponse<DatabaseRecord> | BolticErrorResponse>
Parameters
DatabaseCreateRequest
| Parameter | Type | Required | Description |
|---|---|---|---|
db_name | string | ✅ | Display name of the database |
db_internal_name | string | ❌ | Internal identifier (slug) for the database. If omitted, automatically derived from db_name |
resource_id | string | ❌ | Resource identifier (defaults to "boltic"). For custom resources, use btb-* connector IDs |
Return Value
BolticSuccessResponse<DatabaseRecord>
interface BolticSuccessResponse<DatabaseRecord> {
data: DatabaseRecord;
error: null;
}
DatabaseRecord
interface DatabaseRecord {
id: string; // Unique database identifier (UUID)
account_id: string; // Account identifier
db_name: string; // Display name of the database
db_internal_name: string; // Internal name (slug) used for switching
db_username: string; // Database username
resource_id: string; // Resource identifier
status: "ACTIVE"; // Database status
is_default: boolean; // Whether this is the default database
rank: number; // Database ranking/order
created_by: string; // Creator identifier
updated_by: string; // Last updater identifier
created_at: string; // Creation timestamp (ISO 8601)
updated_at: string; // Last update timestamp (ISO 8601)
}
Examples
Basic Database Creation
import { createClient } from "@boltic/sdk";
const client = createClient("your-api-key");
const { data: database, error } = await client.databases.create({
db_name: "Production Database",
});
if (error) {
console.error("Failed to create database:", error.message);
} else {
console.log("Database created successfully:");
console.log(`- ID: ${database.id}`);
console.log(`- Name: ${database.db_name}`);
console.log(`- Internal Name: ${database.db_internal_name}`);
console.log(`- Status: ${database.status}`);
}
Create Database in Custom Resource
// Create database in a custom resource (connector ID starting with 'btb-')
const { data: customDb, error } = await client.databases.create({
db_name: "Custom Resource Database",
db_internal_name: "custom_resource_db",
resource_id: "btb-abc123xyz", // Your custom connector ID
});
if (error) {
console.error("Failed to create database:", error.message);
} else {
console.log("Custom resource database created:");
console.log(`- Resource ID: ${customDb.resource_id}`);
console.log(`- Database ID: ${customDb.id}`);
}
Best Practices
-
Naming Conventions: Database slugs (
db_internal_name) can only contain letters, numbers, underscores, or hyphens. Use descriptive, lowercase names with underscores or hyphens for readability (e.g.,production_db,dev_environment). -
Resource Selection: Use the default
"boltic"resource for managed databases unless you have a specific requirement for a custom resource. Custom resources require connector setup and are typically used for external database connections. -
Internal Name Planning: If you don't specify
db_internal_name, ensure yourdb_namewill generate a valid slug when auto-derived. Special characters and spaces will be converted or removed. -
Database Organization: Plan your database structure based on your use case - separate databases for different environments (dev, staging, production), projects, or tenants to maintain data isolation.