SQL operation interface

Hierarchy

  • Sql

Properties

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

Type declaration

    • (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.

      Parameters

      • stmt: string

        sql

      • Optional options: SqlOptions

        SQL execution options

      Returns Record[]

      Recordset

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

Type declaration

    • (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.

      Parameters

      Returns ResultSet

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

Type declaration

    • (stmt, options?): Promise<ResultSet>
    • async execute sql, usage please see execute

      Parameters

      Returns Promise<ResultSet>

      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[])

Type declaration

    • (stmt, options?): Record[]
    • Output an SQL execution plan.

      Parameters

      • stmt: string

        sql

      • Optional options: SqlOptions

        Execution Options

      Returns Record[]

      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']});