Skip to main content

Get Database

Retrieve detailed information about a specific database using the database internal name (slug) or by getting the default database. The SDK provides two methods to get database details: findOne() and getDefault().

Method Signatures

// Get database by internal name (slug)
client.databases.findOne(dbInternalName: string, options?: { fields?: string[] }): Promise<BolticSuccessResponse<DatabaseRecord> | BolticErrorResponse>

// Get default database
client.databases.getDefault(): Promise<BolticSuccessResponse<DatabaseRecord> | BolticErrorResponse>

Parameters

findOne Parameters

ParameterTypeRequiredDescription
dbInternalNamestringDatabase internal name (slug)
options{ fields?: string[] }Optional field selection to restrict response

getDefault Parameters

The getDefault() method takes no parameters. It automatically retrieves the account's default database.

Return Value

BolticSuccessResponse<DatabaseRecord>

interface BolticSuccessResponse<DatabaseRecord> {
data: DatabaseRecord;
error: null;
}

DatabaseRecord

All methods return the same DatabaseRecord structure:

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

Get Database by Internal Name

import { createClient } from "@boltic/sdk";

const client = createClient("your-api-key");

const { data: database, error } = await client.databases.findOne("my_database_slug");

if (error) {
console.error("Failed to get database:", error.message);
} else {
console.log("Database details:");
console.log(`- Name: ${database.db_name}`);
console.log(`- Internal Name: ${database.db_internal_name}`);
console.log(`- Status: ${database.status}`);
console.log(`- Is Default: ${database.is_default ? "Yes" : "No"}`);
console.log(`- Created: ${new Date(database.created_at).toLocaleDateString()}`);
}

Get Default Database

// Get the account's default database
const { data: defaultDb, error } = await client.databases.getDefault();

if (error) {
console.error("Failed to get default database:", error.message);
} else {
console.log("Default database details:");
console.log(`- Name: ${defaultDb.db_name}`);
console.log(`- Internal Name: ${defaultDb.db_internal_name}`);
console.log(`- ID: ${defaultDb.id}`);
console.log(`- Status: ${defaultDb.status}`);
console.log(`- Is Default: ${defaultDb.is_default ? "Yes" : "No"}`);
console.log(`- Created: ${new Date(defaultDb.created_at).toLocaleDateString()}`);
}