1.0.1 • Published 1 year ago

@ksfks/oracle-client v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

作用

远程调用oreacleServer ksf服务

用法示例

    var oracleClientHelper = require("@ksfks/oracle-client")("testbus","upapp")

    /**
     * oracle查询
     * @param string   查询SQL语句
     * @param json     JSON格式的绑定数据(如果SQL语句不带绑定标志位,可以不传)
     * @param number   最大查询记录数(如果不传,将读取默认值)
     */

    //如果不带绑定参数,可以只传SQL语句和最大查询数
    oracleClientHelper.query('select * from (select t.*,rownum from UPAPP.NEWS_MAIN_ELE t)', 100).then(data =>{
        console.log(data);
    })

    //最简单时候可以只传一条SQL语句作为参数,此时最大查询数将读取默认值
    oracleClientHelper.query('select * from (select t.*,rownum from UPAPP.NEWS_MAIN_ELE t)').then(data =>{
        console.log(data);
    })

    //绑定数据查询,推荐传入JSON对象,标识符和键值保持一致
    oracleClientHelper.query('select * from UPAPP.STK_BASIC_INFO where STK_UNI_CODE = :skt_uni_code', {skt_uni_code: '2010003382'}, 100).then(data =>{
        console.log(data);
    })

    //如果偷懒的话也可以传数组,不过这样将会按顺序对号入座
    oracleClientHelper.query('select * from UPAPP.STK_BASIC_INFO where STK_UNI_CODE = :skt_uni_code', ['2010003382'], 100).then(data =>{
        console.log(data);
    })

    //兼容了老接口:queryBindParams
    oracleClientHelper.queryBindParams('select * from UPAPP.STK_BASIC_INFO where STK_UNI_CODE = :skt_uni_code', ['2010003382'], 100).then(data =>{
        console.log(data);
    })

    /**
     * oracle查询,加入缓存机制
     *
     * @param json sqlString  查询SQL语句
     *             bindParams JSON格式的绑定数据(如果SQL语句不带绑定标志位,可以不传)
     *             maxRowNum  最大查询记录数,如果不传,读取服务默认配置
     *             expireTime 缓存过期时间,单位秒,如果不传,读取服务默认配置
     *             isForce    是否强刷,如果不传,读取服务默认配置
     */
     
    //最简单的用法,会优先去缓存拿数据,如果没有直接查数据库
    oracleClientHelper.queryCache({
        sqlString:  'select * from UPAPP.STK_BASIC_INFO where STK_UNI_CODE = 2010003382',
    }).then(data => {console.log(data);}).catch(err => {console.log(err);});
     
    //可以限制最大查询数量,如果不传,读取服务默认配置
    oracleClientHelper.queryCache({
        sqlString:  'select * from UPAPP.STK_BASIC_INFO where STK_UNI_CODE = 2010003382',
        maxRowNum:  100
    }).then(data => {console.log(data);}).catch(err => {console.log(err);});
     
    //可以绑定参数
    oracleClientHelper.queryCache({
        sqlString:  'select * from UPAPP.STK_BASIC_INFO where STK_UNI_CODE = :skt_uni_code',
        bindParams: {skt_uni_code: '2010003382'},
        maxRowNum:  100
    }).then(data => {console.log(data);}).catch(err => {console.log(err);});
     
    //同时我们也可以手动设置缓存过期时间,单位秒,如果没设置,读取服务默认配置
    oracleClientHelper.queryCache({
        sqlString:  'select * from UPAPP.STK_BASIC_INFO where STK_UNI_CODE = :skt_uni_code',
        bindParams: {skt_uni_code: '2010003382'},
        maxRowNum:  100,
        expireTime: 60
    }).then(data => {console.log(data);}).catch(err => {console.log(err);});
     
    //服务器配置默认取缓存,如果不想拿缓存的数据,也可以强刷
    oracleClientHelper.queryCache({
        sqlString:  'select * from UPAPP.STK_BASIC_INFO where STK_UNI_CODE = :skt_uni_code',
        bindParams: {skt_uni_code: '2010003382'},
        maxRowNum:  100,
        expireTime: 60,
        isForce:    true
    }).then(data => {console.log(data);}).catch(err => {console.log(err);});

    //最后我们也可以人为指定缓存key
    oracleClientHelper.queryCache({
        sqlString:  'select * from UPAPP.STK_BASIC_INFO where STK_UNI_CODE = :skt_uni_code',
        bindParams: {skt_uni_code: '2010003382'},
        maxRowNum:  100,
        expireTime: 60,
        isForce:    true,
        cacheKey:   'oracle_srv_test'
    }).then(data => {console.log(data);}).catch(err => {console.log(err);});
1.0.1

1 year ago

1.0.0

1 year ago