Update Records
Update existing records in your Boltic Tables with precision and flexibility. The SDK provides multiple approaches for updating records including single record updates and bulk operations with filtering.
Update Operations
The SDK provides two approaches for updating records:
1. Direct Update Operations
updateById() - Update Single Record
Update a specific record by its ID.
client.records.updateById(tableName: string, recordId: string, data: RecordData): Promise<ApiResponse<RecordWithId>>
update() - Bulk Update with Filters
Update multiple records that match specific filter criteria.
client.records.update(tableName: string, options: RecordUpdateOptions): Promise<ApiResponse<RecordWithId[]>>
RecordUpdateOptions Interface
interface RecordUpdateOptions {
set: RecordData; // Data to update
filters?: ApiFilter[] | Record<string, unknown>; // Filter criteria
}
Single Record Updates
Basic Update by ID (Direct Approach)
import { createClient } from "@boltic/sdk";
const client = createClient("your-api-key");
// Update a specific user
const recordId = "rec_123456789";
const updateData = {
name: "John Smith",
email: "[email protected]",
last_login: new Date().toISOString(),
};
const { data: updatedRecord, error } = await client.records.updateById(
"users",
recordId,
updateData,
);
if (error) {
console.error("Update failed:", error.message);
} else {
console.log("Record updated:", updatedRecord.id);
console.log("Updated at:", updatedRecord.updated_at);
}
Partial Updates
// Update only specific fields
const { data: user } = await client.records.updateById("users", recordId, {
last_login: new Date().toISOString(),
login_count: 42,
});
// Update status only
const { data: order } = await client.records.updateById("orders", orderId, {
status: "shipped",
shipped_at: new Date().toISOString(),
});
Field Type Updates
Text and Email Fields
const { data: profile } = await client.records.updateById("profiles", profileId, {
bio: "Updated professional biography with new information.",
email: "[email protected]",
title: "Senior Software Engineer",
});
Number and Currency Fields
const { data: product } = await client.records.updateById("products", productId, {
price: 299.99,
stock_count: 150,
discount_percentage: 15.5,
});
const { data: employee } = await client.records.updateById("employees", employeeId, {
salary: 85000.0,
years_experience: 5,
performance_score: 4.2,
});
Boolean Fields
const { data: user } = await client.records.updateById("users", userId, {
is_active: true,
is_verified: true,
newsletter_subscribed: false,
});
Date-Time Fields
const { data: event } = await client.records.updateById("events", eventId, {
start_date: "2024-06-15T10:00:00Z",
end_date: "2024-06-15T18:00:00Z",
last_modified: new Date().toISOString(),
});
JSON Fields
const { data: settings } = await client.records.updateById("user_settings", settingsId, {
preferences: {
theme: "dark",
language: "en-US",
notifications: {
email: true,
push: false,
sms: true,
},
},
metadata: {
version: "2.1",
last_sync: new Date().toISOString(),
},
});
Dropdown/Selection Fields
const { data: task } = await client.records.updateById("tasks", taskId, {
priority: ["high"], // Single selection
tags: ["urgent", "backend", "bug-fix"], // Multiple selection
status: "in-progress",
});
Vector Fields
const { data: document } = await client.records.updateById("documents", documentId, {
content_vector: [0.1, 0.2, 0.3, 0.4, 0.5],
title_vector: [0.2, 0.3, 0.4, 0.5, 0.6],
sparse_features: "{1:0.8,3:0.6,5:0.9}/5",
});
Bulk Update Operations
Update with Simple Filters
// Update all inactive users
const { data: updatedUsers, error } = await client.records.update("users", {
set: {
status: "archived",
archived_at: new Date().toISOString(),
},
filters: {
status: "inactive",
last_login: { $lt: "2023-01-01T00:00:00Z" },
},
});
console.log(`Updated ${updatedUsers.length} users`);
Update with Complex Filters
import { createFilter } from "@boltic/sdk";
// Update products with complex criteria
const productFilters = createFilter()
.equals("category", "electronics")
.lessThan("stock_count", 10)
.equals("is_active", true)
.build();
const { data: updatedProducts } = await client.records.update("products", {
set: {
status: "low-stock",
needs_reorder: true,
last_inventory_check: new Date().toISOString(),
},
filters: productFilters,
});
Update with ApiFilter Format
// Update orders using ApiFilter format
const { data: updatedOrders } = await client.records.update("orders", {
set: {
status: "processing",
processing_started: new Date().toISOString(),
},
filters: [
{ field: "status", operator: "=", values: ["pending"] },
{ field: "payment_status", operator: "=", values: ["confirmed"] },
{ field: "created_at", operator: ">", values: ["2024-01-01T00:00:00Z"] },
],
});
Bulk Operations for Large Updates
// Efficient: Use bulk updates for multiple records
const { data: updatedUsers } = await client.records.update("users", {
set: {
notification_enabled: true,
updated_at: new Date().toISOString(),
},
filters: {
role: { $in: ["admin", "moderator"] },
is_active: true,
},
});
// Less efficient: Individual updates
// for (const user of adminUsers) {
// await client.records.updateById('users', user.id, { notification_enabled: true });
// }
Response Format
Successful Single Update Response
interface BolticSuccessResponse<RecordWithId> {
data: {
id: string; // Record ID
created_at: string; // Original creation timestamp
updated_at: string; // Latest update timestamp
[fieldName: string]: unknown; // Updated record data
};
error: null;
}
Successful Bulk Update Response
interface BolticListResponse<RecordWithId> {
data: RecordWithId[]; // Array of updated records
pagination?: {
// If applicable
current_page: number;
total_pages: number;
total_count: number;
page_size: number;
};
error: null;
}
Error Response
interface BolticErrorResponse {
data: null;
error: {
message: string; // Human-readable error message
meta?: string[];
};
}