1.9.29 • Published 3 days ago

bonsaif v1.9.29

Weekly downloads
-
License
MIT
Repository
-
Last release
3 days ago

Eliminar publicacion npm unpublish bonsaif@1.9.23

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)+']');

License

MIT

1.9.29

3 days ago

1.9.28

4 days ago

1.9.27

4 days ago

1.9.26

4 days ago

1.9.25

7 days ago

1.9.24

1 month ago

1.9.23

1 month ago

1.9.22

1 month ago

1.9.21

1 month ago

1.9.20

1 month ago

1.9.19

1 month ago

1.9.18

1 month ago

1.9.1-8.1

1 month ago

1.9.17

1 month ago

1.9.16

1 month ago

1.9.15

2 months ago

1.9.14

2 months ago

1.9.12

2 months ago

1.9.11

5 months ago

1.9.10

5 months ago

1.9.9

5 months ago

1.9.1

8 months ago

1.9.0

9 months ago

1.9.8

5 months ago

1.9.7

6 months ago

1.9.6

6 months ago

1.9.5

7 months ago

1.9.4

8 months ago

1.9.3

8 months ago

1.9.2

8 months ago

1.8.9

9 months ago

1.8.8

9 months ago

1.8.7

9 months ago

1.8.6

9 months ago

1.7.9

12 months ago

1.8.2

12 months ago

1.8.1

12 months ago

1.8.0

12 months ago

1.8.5

12 months ago

1.8.4

12 months ago

1.8.3

12 months ago

1.7.8

1 year ago

1.7.7

1 year ago

1.7.6

1 year ago

1.7.5

1 year ago

1.7.4

1 year ago

1.7.3

1 year ago

1.7.2

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.4

1 year ago

1.6.3

1 year ago

1.6.2

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.9

1 year ago

1.6.9

1 year ago

1.6.8

1 year ago

1.6.7

1 year ago

1.6.6

1 year ago

1.6.5

1 year ago

1.5.8

1 year ago

1.5.7

1 year ago

1.5.6

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.9

2 years ago

1.4.8

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.7

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.4.2

2 years ago

1.2.4

2 years ago

1.4.1

2 years ago

1.2.3

2 years ago

1.4.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.3.8

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.3.7

2 years ago

1.1.9

2 years ago

1.3.6

2 years ago

1.1.8

2 years ago

1.3.5

2 years ago

1.1.7

2 years ago

1.3.4

2 years ago

1.1.6

2 years ago

1.3.3

2 years ago

1.1.5

2 years ago

1.3.2

2 years ago

1.1.4

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.1.2

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.2.9

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago