Get Table
Retrieve detailed information about a specific table using the table ID or name. The Boltic Tables SDK provides multiple methods to get table details: findById()
, findByName()
, and findOne()
.
Method Signatures
// Get table by ID
client.tables.findById(id: string): Promise<ApiResponse<TableRecord>>
// Get table by name
client.tables.findByName(name: string): Promise<ApiResponse<TableRecord>>
// Get table with custom query
client.tables.findOne(options: TableQueryOptions): Promise<ApiResponse<TableRecord>>
Parameters
findById Parameters
Parameter | Type | Required | Description |
---|---|---|---|
id | string | ✅ | Unique table identifier |
findByName Parameters
Parameter | Type | Required | Description |
---|---|---|---|
name | string | ✅ | Table name |
findOne Parameters
Parameter | Type | Required | Description |
---|---|---|---|
options | TableQueryOptions | ✅ | Query options (must identify a single table) |
Return Value
All methods return the same TableRecord
structure:
interface TableRecord {
id: string; // Unique table identifier
name: string; // Table name
account_id: string; // Account identifier
internal_db_name: string; // Database name
db_id?: string; // Database UUID
resource_id?: string; // Resource identifier
description?: string; // Table description
type?: string; // Table type
parent_table_id?: string; // Parent table reference
is_deleted: boolean; // Soft-delete status
is_public: boolean; // Public visibility
created_by: string; // Creator identifier
created_at: string; // Creation timestamp
updated_at: string; // Last update timestamp
updated_by: string; // Last updater identifier
source?: "boltic" | "copilot"; // Creation source
account_status?: "active" | "suspended" | "deleted"; // Account status
}
Examples
Get Table by ID
import { createClient } from "@boltic/sdk";
const client = createClient("your-api-key");
const { data: table, error } = await client.tables.findById("table_uuid");
if (error) {
console.error("Failed to get table:", error.message);
} else {
console.log("Table details:");
console.log(`- Name: ${table.name}`);
console.log(`- Description: ${table.description || "No description"}`);
console.log(`- Created: ${new Date(table.created_at).toLocaleDateString()}`);
console.log(`- Public: ${table.is_public ? "Yes" : "No"}`);
}
Get Table by Name
// Get table using name (most common approach)
const { data: usersTable, error } = await client.tables.findByName("users");
if (error) {
console.error("Error:", error.message || error.meta);
} else {
console.log(`Found table: ${usersTable.name} (${usersTable.id})`);
}
Get Table with Custom Query
// Find table with specific conditions
const { data: table, error } = await client.tables.findOne({
where: {
name: "products",
is_public: true,
},
});
Practical Use Cases
Table Validation Before Operations
async function validateTableExists(tableName: string): Promise<boolean> {
const { data: table, error } = await client.tables.findByName(tableName);
if (error) {
console.error("Error:", error.message || error.meta);
return false;
}
return true;
}
// Usage
if (await validateTableExists("products")) {
// Proceed with operations on products table
const { data: records } = await client.records.findAll("products");
} else {
console.log("Cannot proceed - table not available");
}
Comparison of Methods
When to Use Each Method
Method | Use Case | Example |
---|---|---|
findById() | When you have the table ID from a previous operation | Getting table after creation |
findByName() | When you know the table name (most common) | User-facing table selection |
findOne() | When you need custom filtering or sorting | Finding table by complex criteria |