Inserting Data in Batches
ID list of records that are successfully inserted.
import * as db from 'db';
let s = db.object('Student__CST');
let records = [
{"name": "Tom","age__CST": "13"},
{"name": "Jerry","age__CST": "12"},
];
let ids = s.batchInsert(record);
Batch Update Records
string[] ids of the inserted records
import * as db from 'db';
let s = db.object('Student__CST');
let records = [
{"id":"00da000000f2scP5Bw36", "name": "Tom_t"},
{"id":"00da000000f2scP5Bw37", "name": "Jerry_j"},
];
let ids = s.batchUpdate(record);
Creating Parent-Child Object Combination Records in Batches
Insert the record set ID list.
import * as db from 'db';
let s = db.object('Customer__CST');
// Parent and child records need to be associated with each other through associated fields.
// For example, the following records are associated with each other through `Contacts` to
// form a combined record.
let records = [ {
"name": "hello",
"count__CST": 123,
"Contacts": {
"records": [
{
"name": "hello_contact1"
},
{
"name": "hello_contact2"
}]
}
}];
let ids = s.compositeInsert(records);
console.log("id list = ", ids);
Count the number of records that meet the condition.
Optional
condition: ConditionMatching condition
Number of records that meet the conditions
import * as db from 'db';
let s = db.object('Student__CST');
let cond = {
conjunction: db.Conjunction.AND,
conditions: [
{
field: "age__CST",
"operator": db.Operator.lt,
"value": 10
}
]
}
let num = s.count(cond);
Deletes records by ID.
Record ID.
Optional
flag: FlagOperation flag
Number of records affected
Delete records based on conditions.
Number of records affected
import * as db from 'db';
let s = db.object('Student__CST');
let cond = {
conjunction: db.Conjunction.AND,
conditions: [
{
field: "name",
operator: db.Operator.eq,
value: "Tom"
}
]
}
let num = s.deleteByCondition(cond);
Newly added records
Specifies the ID of a new record.
Query records by ID.
Record ID.
Optional
option: "db".OptionQuery option. In the case of query by ID, you can specify the query field set. Other options have no effect.
Optional
relation: RelationParent-child relationship. If the parent-child relationship needs to be queried in cascading mode, you need to specify
import * as db from 'db';
let s = db.object('Student__CST');
let id = '00da000000f2scP5Bw36';
let option = {
options: {
fields: ["name", "age", "grade"],
}
};
let record = s.query(id, option);
Query records by condition. The number of returned records can be limited. The skip value specifies the number of records from which the query starts, and the limit value specifies the number of returned records.
If skip and limit are not specified, the default values are skip=0 and limit=5000, indicating that the first 5000 records in the result set are returned. The maximum limit can be set to 10000, indicating that the query interface can return only the first 10000 records in the query result set.
Recordsets that meet the conditions
import * as db from 'db';
let s = db.object('Student__CST');
let cond = {
conjunction: db.Conjunction.AND,
conditions:[
{
field: "age__CST",
operator: db.Operator.lt,
"value": 10
}
]
}
let records = s.queryByCondition(cond);
Updates records by ID.
Number of records affected
Update records based on conditions
Number of records affected
import * as db from 'db';
let s = db.object('Student__CST');
let cond = {
conjunction: db.Conjunction.AND,
conditions: [
{
field: "name",
operator: db.Operator.eq,
value: "Tom"
}
]
}
let record = {
"name": "NewTom",
"age__CST": "14"
};
let num = s.updateByCondition(cond, record);
Object wrapper