bonsaif
v1.9.47
Published
bonsaif is a library to connect to bonsaif apis
Downloads
502
Maintainers
Readme
Eliminar publicacion npm unpublish [email protected]
bonsaif.js
bonsaif t is a library to connect to bonsaif apis
Installation
npm install bonsaif
Examples
Here is the first one to get you started:
const bonsaif = require('bonsaif');
// utl,
const {utl} = require('bonsaif');
//ec
const {ec} = require('bonsaif');
const tag = "test";
// ./cnf/endpoint.js
const endpointMariaDB= {
uri: '',
user: '',
password: '',
client:'mariadb'
};
const localMariaDB= {
uri:'',
port: '',
user:'',
password:'',
local:true,
debug:false,
client:'mariadb'
};
// Execute query
const run =async()=>{
//localhost
let rs = await bonsaif.query({endpoint:localMariaDB, options:{db:'', sys:''}, query:'select * from table', tag});
//endpoint
let rs = await bonsaif.query({endpoint:endpointMariaDB, options:{db:'', sys:''}, query:'select * from table', tag});
while (rs.next()){
utl.log('row json',rs.row);
let x = rs.row;
utl.log('get field ['+x+']');
utl.log('get field ['+rs.get('column')+']');
utl.log('get field by Index ['+rs.get(0)+']');
}
}
run();
/**
* Execute mongodb
* https://www.mongodb.com/docs/manual/reference/command/
**/
const endpointMongo= {
uri: '',
user: '',
password: '',
client:'mongodb'
};
const localMongo= {
uri:'',
poolSize:8,
local:true,
debug:false,
client:'mongodb'
};
const runMongo =async()=>{
// localhost
let insert = await bonsaif.query({endpoint:localMongo, options:{db:'', sys:''}, query:{insert: "collection", documents: [{ 'id':1, 'ds':'demo1' }]}, tag});
//endpoint
let insert = await bonsaif.query({endpoint:endpointMongo, options:{db:'', sys:''}, query:{insert: "collection", documents: [{ 'id':1, 'ds':'demo1' }]}, tag});
let find = await bonsaif.query({endpoint:endpointMongo, options:{db:'', sys:''}, query:{find: "collection", filter: { 'id':1 }}, tag});
let update = await bonsaif.query({endpoint:endpointMongo, options:{db:'', sys:''}, query:{update: "collection", filter: { _id:1 } documents: [{ "id":1, "ds":"ds Change", "NewC":1 }]}, tag});
let upsert = await bonsaif.query({endpoint:endpointMongo, options:{db:'', sys:''}, query:{upsert: "collection", filter: { _id:1 }, document:{ 'id':1, 'ds':'ds1', 'live':0 } }, tag});
}
runMongo();
/**
* Execute redis
* https://redis.io/commands/?group=set
**/
const endpointRedis= {
uri: '',
user: '',
password: '',
client:'redis'
};
const localRedis= {
uri:'',
local:true,
debug:false,
client:'redis'
};
const runRedis =async()=>{
let redis;
// localhost
redis = await bonsaif.query({endpoint:localRedis, options:{db:'', sys:''} query:{set:"Key:Test", value:"123456"}, tag:'test'});
utl.log('set ',redis);
//endpoint
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{set:"Key:Test", value:"123456"}, tag:'test'});
utl.log('set ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{set:"Key:Expire", value:"123456", expire:20}, tag:'test'});
utl.log('set expire ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{get:"Key:Test"}, tag:'test'});
utl.log('get ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{scan:"log*"}, tag:'test'});
utl.log('scan ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{upsert:"log:test", value:{"id_":1, "ds":"ds", live:1, "child_id":2}, filter:{"id_":1}}, tag:'test'});
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{upsert:"log:test", value:{"id_":2, "ds":"ds2", live:1, "child_id":2}, filter:{"id_":2}}, tag:'test'});
utl.log('upsert (sadd) ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hfind:"log:test", filter:{"id_":"*"} }, tag:'test'});
utl.log('hfind (smembers) ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hfind:"log:test", filter:{"id_":"1"} }, tag:'test'});
utl.log('hfind (smembers) ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hfind:"log:test", filter:{$and:[{"id_":1},{"child_id":"2"}]},}, tag:'test'});
utl.log('hfind (smembers) ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hfind:"log:test", filter:{$or:[{"id_":1},{"child_id":"2"}]},}, tag:'test'});
utl.log('hfind (smembers) ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hfind:"log:test", filter:{"id_":{$in:[1,2]}}}, tag:'test'});
utl.log('in (smembers) ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{set:"Key:Test:Del", value:"123456"}, tag:'test'});
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{del:"Key:Test:Del" }, tag:'test'});
utl.log('del ',redis);
//redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{del:"Total" }, tag:'test'});
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{incrby:"Total", value:1000, counter:1 }, tag:'test'});
utl.log('incrby ',redis);
//redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{del:"Total:Float" }, tag:'test'});
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{incrbyfloat:"Total:Float", value:1000.00, counter:-5.1 }, tag:'test'});
utl.log('TotalFloat ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{sadd:"Member", "value":"1" }, tag:'test'});
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{sadd:"Member", "value":"2" }, tag:'test'});
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{sadd:"Member", "value":"3" }, tag:'test'});
utl.log('sadd ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{smembers:"Member", "value":"2" }, tag:'test'});
utl.log('smembers ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{srem:"Member", "value":"2" }, tag:'test'});
utl.log('srem ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hset:"hset", "value":{"id_cli":"1000","username":"1","password": "2", "A":"1" } }, tag:'test'});
utl.log('hset ',redis);
redis = await bonsaif.query({endpoint:endpointRedis, options:{db:'1', sys:'cc2'}, query:{hgetall:"hset"}, tag:'test'});
utl.log('hgetall ',redis);
}
runRedis();
utl.log('custom log '+utl.date()+' '+utl.hour());
/**
* Encript
**/
let key = ec.StringToHex('keyString');
utl.log('['+ec.fromHexString(key)+']');
let keyKP = ec.StringToHexKP('llave','keyStringKP');
utl.log('['+ec.fromHexStringKP('llave',keyKP)+']');