ym-dbhelper
v2.5.0
Published
用参数调用数据库
Downloads
4
Readme
dbHelper
这是一个数据库执行SQL(参数形式),具体某种库在具体 ym-dhhelper-xxxx 中具体实现
ym-dhhelper-sqlite3 ym-dhhelper-mysql
初始化sqlite
const engineName = 'sqlite'; // sqlite/better-sqlite/mysql/mssql/oracle
const cnnParamSqlite = {
file: path.join(__dirname, './demosl3/demo.sl3'),
}
const dhOption = { trace: true }
const db_sl3 = dhHelper.create(engineName, cnnParamSqlite, dhOption);
初始化better-sqlite
const engineName = 'better-sqlite'; // sqlite/better-sqlite/mysql/mssql/oracle
const cnnParamSqlite = {
file: path.join(__dirname, './demosl3/demo.sl3'),
}
const dhOption = { trace: true } //日志
const db_sl3 = dhHelper.create(engineName, cnnParamSqlite, dhOption);
连接参数
const mssqlCnnParam = {
server: '127.0.0.1',
user: 'sa',
password: 'haosql',
database: 'yg_test',
pool: {
min: 0,
max: 10
},
};
const mysqlCnnParam = {
connectionLimit: 10,
waitForConnections: true, //若没有空闲连接 等待 false 不等待 //https://github.com/mysqljs/mysql#pooling
host: '127.0.0.1',
user: 'root',
password: 'haosql',
database: 'ygtest'
}
const sqliteCnnParam = {
file: path.join(__dirname, '../../../demoApp/app/db/demoApp.sl3'),
engine:'better-sqlite3',//使用 better-sqlite3 模块速度快的多 若没有配置此项 使用 node-sqlite3模块
}
初始化
const dh = require('dbhelper');
const db = dh.create('mysql', mysqlCnnParam, { trace: true });
调用
const sqlOBj_demo = {
sql: 'select * from a_dict where (kind=:KIND)',
params: 't4', //paramsObj 两种形式 一种数组 [v1,v2] 另一种是对象 {paramname1:v1,paramname2:v2,}
is方言: false,
dynFilter: { k: '%223%', V: 'a', },//动态过滤参数 可选
isQuery:true ,//||false //是否查询
page: { page: 1, rows: 3, },//分页 可选
sortby: { LCT: 'asc', V: 'desc' }
};
dbHelper.execSqlObjs(sqlObj, function (err, ret) {
});
//ret格式
const ret = {
info: {
changes: 0 ,
lastID:1 //
},
pageTotalCount:1000, //分页查询时的总页数
rows: []
};