database instance

TIP

Database Instance

beginTransaction ()

开启事务

  • 返回 无

    例 :

 const beginTransactionResult = await instance.beginTransaction()

close ()

关闭连接

  • 返回 无

    例 :

 const closeResult = await instance.close()

commit ()

提交事务

  • 返回 无

    例 :

 const commitResult = await instance.commit()

count (sql, param)

计数

注意

Mssql和Mysql 使用 ? 作为参数
Oracle 使用 :0 作为参数

参数类型作用备注
sqlarray需要执行的SQL
paramstringSQL参数

例 :

 const sql = `select * from test_table where code =? and name =?`
 const params = ['adc','张三']
 const count = await instance.count(sql, params)

execute (sql, param)

执行SQL

  • 返回 无

注意

Mssql和Mysql 使用 ? 作为参数
Oracle 使用 :0 作为参数

参数类型作用备注
sqlarray需要执行的SQL
paramstringSQL参数

例 :

 const sql = `select * from test_table where code =? and name =?`
 const params = ['adc','张三']
 await instance.execute(sql, dataList)

executeBatch (sql, paramList)

批量执行

  • 返回 无

注意

Mssql和Mysql 使用 ? 作为参数
Oracle 使用 :0 作为参数

参数类型作用备注
sqlarray需要执行的SQL
paramListstringSQL参数

例 :

 const sql = `select * from test_table where code =? and name =?`
 const paramList = [
  ['adc','张三'],
  ['def','李四']
]
 await instance.executeBatch(sql, paramList)

query (sql, param)

查询

注意

Mssql和Mysql 使用 ? 作为参数
Oracle 使用 :0 作为参数

参数类型作用备注
sqlarray需要执行的SQL
paramsstringSQL参数

例 :

 const sql = `select * from test_table where code =? and name =?`
 const params = ['adc','张三']
 const queryResult = await instance.query( sql, params)

queryPage (sql, param, page, size)

分页查询

注意

Mssql和Mysql 使用 ? 作为参数
Oracle 使用 :0 作为参数

参数类型作用备注
sqlarray需要执行的SQL
paramstringSQL参数
pagenumber页数从0计数
sizenumber每页条数

例 :

 const sql = `select * from test_table where code =? and name =?`
 const params = ['adc','张三']
 const list = await instance.queryPage(sql, dataList,0,100)

rollback ()

回滚事务

  • 返回 无

    例 :

 const rollbackResult = await instance.rollback()