Add data
Initialize SDK
import cloudbase from "@cloudbase/js-sdk";
const app = cloudbase.init({
env: "your-env-id", // Replace this value with your environment ID
});
const models = app.models
Add a single record
Add a new record to the data model.
models.modelName.add(options)
- modelName: name of the data model
- options: add parameter
options parameter description
| Parameter | Type | Required | Description |
|---|---|---|---|
| data | object | Yes | New data object to add |
Sample Code
Create a single record
const todo = await models.todo.create({
data: {
title: "Client task"
description: "Task created using js-sdk"
priority: "high",
completed: false,
createdAt: new Date(),
createdBy: "system",
metadata: {
source: "api",
version: "1.0"
}
}
})
console.log('Creation succeeded:', todo)
Batch Add
Add multiple records to the data model at once.
⚠️ Note: Batch queries not supported for adding new association relationship fields
models.modelName.createMany(options)
- modelName: name of the data model
- options: add parameter
options parameter description
| Parameter | Type | Required | Description |
|---|---|---|---|
| data | array | Yes | Array containing multiple data objects |
Sample Code
Batch create multiple records
const todos = await models.todo.createMany({
data: [{
title: "Batch Task 1"
priority: "high"
},
{
title: "Batch Task 2"
priority: "medium"
},
{
title: "Batch Task 3"
priority: "low"
}
]
})
console.log('Batch creation succeeded:', todos)