Object wrapper

interface Orm {
    batchInsert: ((records, flag?) => string[]);
    batchUpdate: ((records, flag?) => string[]);
    compositeInsert: ((records, flag?) => Record[]);
    count: ((condition?) => number);
    delete: ((id, flag?) => number);
    deleteByCondition: ((condition, flag?) => number);
    insert: ((record, flag?) => string);
    query: ((id, option?, relation?) => Record);
    queryByCondition: ((condition, option?, relation?) => Record[]);
    update: ((id, record, flag?) => number);
    updateByCondition: ((condition, record, flag?) => number);
}

Properties

batchInsert: ((records, flag?) => string[])

Inserting Data in Batches

Type declaration

    • (records, flag?): string[]
    • Parameters

      • records: Record[]

        Recordset

      • Optional flag: Flag

        Transaction flag

      Returns string[]

Returns

ID list of records that are successfully inserted.

Example


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);
batchUpdate: ((records, flag?) => string[])

Batch Update Records

Type declaration

    • (records, flag?): string[]
    • Parameters

      • records: Record[]

        Recordset

      • Optional flag: Flag

        Transaction flag

      Returns string[]

Returns

string[] ids of the inserted records

Example


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);
compositeInsert: ((records, flag?) => Record[])

Creating Parent-Child Object Combination Records in Batches

Type declaration

    • (records, flag?): Record[]
    • Parameters

      • records: Record[]

        Parent-child object combination record array

      • Optional flag: Flag

        Transaction flag

      Returns Record[]

Returns

Insert the record set ID list.

Example


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: ((condition?) => number)

Count the number of records that meet the condition.

Type declaration

    • (condition?): number
    • Parameters

      • Optional condition: Condition

        Matching condition

      Returns number

Returns

Number of records that meet the conditions

Example


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);
delete: ((id, flag?) => number)

Deletes records by ID.

Type declaration

    • (id, flag?): number
    • Parameters

      • id: string

        Record ID.

      • Optional flag: Flag

        Operation flag

      Returns number

Returns

Number of records affected

deleteByCondition: ((condition, flag?) => number)

Delete records based on conditions.

Type declaration

    • (condition, flag?): number
    • Parameters

      • condition: Condition

        Matching condition

      • Optional flag: Flag

        Operation flag

      Returns number

Returns

Number of records affected

Example


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);
insert: ((record, flag?) => string)

Newly added records

Type declaration

    • (record, flag?): string
    • Parameters

      • record: Record

        Recording

      • Optional flag: Flag

        Operation flag

      Returns string

Returns

Specifies the ID of a new record.

query: ((id, option?, relation?) => Record)

Query records by ID.

Type declaration

    • (id, option?, relation?): Record
    • Parameters

      • id: string

        Record ID.

      • Optional option: "db".Option

        Query option. In the case of query by ID, you can specify the query field set. Other options have no effect.

      • Optional relation: Relation

        Parent-child relationship. If the parent-child relationship needs to be queried in cascading mode, you need to specify

      Returns Record

Example


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);
queryByCondition: ((condition, option?, relation?) => Record[])

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.

Type declaration

    • (condition, option?, relation?): Record[]
    • Parameters

      • condition: Condition

        Matching condition

      • Optional option: "db".Option

        Query Options

      • Optional relation: Relation

        Parent-Child Object Relationship

      Returns Record[]

Returns

Recordsets that meet the conditions

Example


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);
update: ((id, record, flag?) => number)

Updates records by ID.

Type declaration

    • (id, record, flag?): number
    • Parameters

      • id: string

        Record ID.

      • record: Record

        What needs to be updated

      • Optional flag: Flag

        Operation flag

      Returns number

Returns

Number of records affected

updateByCondition: ((condition, record, flag?) => number)

Update records based on conditions

Type declaration

    • (condition, record, flag?): number
    • Parameters

      • condition: Condition

        Matching condition

      • record: Record

        What needs to be updated

      • Optional flag: Flag

        Operation flag

      Returns number

Returns

Number of records affected

Example


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);