Skip to content

sql

Use db.sql to perform SQL operations.

Only the following query is supported:selectOperation. Not supportedDMLOperation:insert,update,deletestatement

Use the

Query by page

Use the'limit offset, count' statement to perform query pagination,

The number of returned records can be limited. The offset value is used to specify the number of records from which the query starts and the count value is used to specify the 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 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.

ts
import * as db from 'db';

@useObject(['student__cst'])
class Demo {
    test(): void {
        let value = db.sql().execute("select name, age__CST from student__CST where age__CST > ? limit 10, 1000", { params: [12] });
    }
}

let demo = new Demo();
demo.test();

Parameter Binding

To solve common SQL injection problems, SQL supports parameter binding.

ts
import * as db from 'db';

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

let demo = new Demo();
demo.test();
  • in statement parameter binding

If in has several parameter values, you need to have several parameter values.?No.

ts
import * as db from 'db';

@useObject(['student__cst'])
class Demo {
    test(): void {
        let value = db.sql().execute("select name, age__CST from student__CST where name in (?, ?, ?)", { params: ['name1', 'name2', 'name3']});
    }
}

let demo = new Demo();
demo.test();
  • The limit statement does not support parameter binding.

That is, not supportedlimit ?, ?, and then pass in the dynamic binding operation of the parameter.