基于 sqlite 3 实现的 数据库存储能力.
执行单条 SQL 语句
参数名 | 类型 | 是否可选 | 默认值 | 含义 |
---|---|---|---|---|
options |
Object |
选项 | ||
options.query |
Object |
请求参数 | ||
options.query.sql |
String Array |
SQL 语句 或 SQL 语句和参数的组合数组 | ||
options.query.sql[0] |
String |
SQL 语句 | ||
options.query.sql[1] |
Array |
执行 SQL 语句同时传入的参数 | ||
options.success |
Function |
可选 | 调用成功的回调函数 | |
options.error |
Function |
可选 | 调用失败的回调函数 |
参数名 | 类型 | 是否必须返回 | 含义 |
---|---|---|---|
result |
Object |
响应对象 | |
result.code |
String |
错误码,成功为 QAP_SUCCESS ;失败为其他 |
|
result.msg |
String |
错误信息 |
// 直接执行 SQL 语句 QN.database.execSql({ query: { sql: 'CREATE TABLE IF NOT EXISTS Employee(id integer PRIMARY KEY AUTOINCREMENT,name varchar,sex varchar,departmentId integer)', } }).then((result) => { console.log(result); }, (error) => { console.log(error); }); QN.database.execSql({ query: { sql: 'CREATE TABLE IF NOT EXISTS Employee(id integer PRIMARY KEY AUTOINCREMENT,name varchar,sex varchar,departmentId integer)', }, success(result) { console.log(result); }, error(error) { console.log(error); } });
// 执行 SQL 语句并传入参数,传入的数据会取代 SQL 语句中的 `?` QN.database.execSql({ query: { sql: ['INSERT INTO Employee (name,sex,departmentId) VALUES (?,?,?)', ['张三', '男', 10003]], } }).then((result) => { console.log(result); }, (error) => { console.log(error); }); QN.database.execSql({ query: { sql: ['INSERT INTO Employee (name,sex,departmentId) VALUES (?,?,?)', ['张三', '男', 10003]], }, success(result) { console.log(result); }, error(error) { console.log(error); } });
批量执行 SQL 语句
执行单条 SQL 语句
参数名 | 类型 | 是否可选 | 默认值 | 含义 |
---|---|---|---|---|
options |
Object |
选项 | ||
options.query |
Object |
请求参数 | ||
options.query.sql |
Array |
SQL 数组 | ||
options.query.sql[i] |
String |
QN.database.execSql 中 sql 的任一形式 |
||
options.success |
Function |
可选 | 调用成功的回调函数 | |
options.error |
Function |
可选 | 调用失败的回调函数 |
参数名 | 类型 | 是否必须返回 | 含义 |
---|---|---|---|
result |
Object |
响应对象 | |
result.code |
String |
错误码,成功为 QAP_SUCCESS ;失败为其他 |
|
result.msg |
String |
错误信息 |
QN.database.batchSql({ query: { sql: [ ['INSERT INTO Employee (name,sex,departmentId) VALUES (?,?,?)', ['张三', '男', 10003]], ['INSERT INTO Employee (name,sex,departmentId) VALUES (?,?,?)', ['李四', '男', 10004]], ['DELETE FROM Employee WHERE sex = "女"'], ] } }).then((result) => { console.log(result); }, (error) => { console.log(error); }); QN.database.batchSql({ query: { sql: [ ['INSERT INTO Employee (name,sex,departmentId) VALUES (?,?,?)', ['张三', '男', 10003]], ['INSERT INTO Employee (name,sex,departmentId) VALUES (?,?,?)', ['李四', '男', 10004]], ['DELETE FROM Employee WHERE sex = "女"'], ] }, success(result) { console.log(result); }, error(error) { console.log(error); } });