SQL operation interface

interface Sql {
    exec: ((stmt, options?) => Record[]);
    execute: ((stmt, options?) => ResultSet);
    executeAsync: ((stmt, options?) => Promise<ResultSet>);
    explain: ((stmt, options?) => Record[]);
}

Properties

exec: ((stmt, options?) => Record[])

Run the limit offset, count statement to perform pagination query, The number of records to be returned can be limited. The offset value is used to specify the number of records to be returned and the count value is used to specify the number of records to be returned.

If offset and count are not specified, the default values are offset=0 and count=5000, indicating that the first 5000 records in the result set are returned. The maximum number of count records can be set to 10000, indicating that the query interface can return only the first 10000 records in the query result set.

Type declaration

    • (stmt, options?): Record[]
    • Parameters

      • stmt: string

        sql

      • Optional options: SqlOptions

        SQL execution options

      Returns Record[]

Returns

Recordset

execute: ((stmt, options?) => ResultSet)

Run the SQL statement and use the'limit offset, count' statement to query the pagination, The number of returned records can be limited. The offset value specifies the start record, and the count value specifies the total number of returned records. If offset and count are not specified, the default values are offset=0 and count=5000, indicating that the first 5000 records in the result set are returned. The maximum value of count is 10000, indicating that the query interface can return only the first 10000 query results.

Type declaration

Example


import * as db from 'db';

@useObject(['student__cst'])
class Demo {
run: () => void {
let se = db.sql();
let sql = "select name, age__CST from student__CST where name = ? and age__CST = ?";
let value = se.execute(sql, { params: ['hello2', 'age2']});
}
}

let demo = new Demo();
demo.run();
executeAsync: ((stmt, options?) => Promise<ResultSet>)

async execute sql, usage please see execute

Type declaration

Since

24.7.0 only js2.0 support

Example


import * as db from 'db';

@useObject(['student__cst'])
class Demo {
run: () => void {
let se = db.sql();
let sql = "select name, age__CST from student__CST where name = ? and age__CST = ?";
let value = await se.executeAsync(sql, { params: ['hello2', 'age2']});
}
}

let demo = new Demo();
demo.run();
explain: ((stmt, options?) => Record[])

Output an SQL execution plan.

Type declaration

    • (stmt, options?): Record[]
    • Parameters

      • stmt: string

        sql

      • Optional options: SqlOptions

        Execution Options

      Returns Record[]

Returns

Execution plan information

Example


import * as db from 'db';
let se = db.sql();
let plans = se.explain(
"select name, age__CST from student__CST where name = ? and age__CST = ?", { params: ['hello2', 'age2']});