2.5.0 • Published 2 months ago

ym-dbhelper v2.5.0

Weekly downloads
4
License
ISC
Repository
-
Last release
2 months ago

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: []
};
2.5.0

2 months ago

2.4.1

10 months ago

2.4.0

10 months ago

2.3.0

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.3

4 years ago

2.1.0

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago