1.10.12 • Published 5 months ago

bonsaif v1.10.12

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months 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.10.12

5 months ago

1.10.11

6 months ago

1.10.10

7 months ago

1.10.9

8 months ago

1.10.8

8 months ago

1.10.7

8 months ago

1.10.6

8 months ago

1.10.5

8 months ago

1.10.4

8 months ago

1.10.3

8 months ago

1.10.2

8 months ago

1.10.1

8 months ago

1.9.49

9 months ago

1.9.48

9 months ago

1.9.47

9 months ago

1.9.46

10 months ago

1.9.45

10 months ago

1.9.44

11 months ago

1.9.43

12 months ago

1.9.42

12 months ago

1.9.41

12 months ago

1.9.40

1 year ago

1.9.39

1 year ago

1.9.38

1 year ago

1.9.37

1 year ago

1.9.36

1 year ago

1.9.35

1 year ago

1.9.34

1 year ago

1.9.33

1 year ago

1.9.32

1 year ago

1.9.31

1 year ago

1.9.30

1 year ago

1.9.29

1 year ago

1.9.28

1 year ago

1.9.27

1 year ago

1.9.26

1 year ago

1.9.25

1 year ago

1.9.24

1 year ago

1.9.23

1 year ago

1.9.22

1 year ago

1.9.21

1 year ago

1.9.20

1 year ago

1.9.19

1 year ago

1.9.18

1 year ago

1.9.1-8.1

1 year ago

1.9.17

1 year ago

1.9.16

1 year ago

1.9.15

1 year ago

1.9.14

1 year ago

1.9.12

1 year ago

1.9.11

2 years ago

1.9.10

2 years ago

1.9.9

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.9.8

2 years ago

1.9.7

2 years ago

1.9.6

2 years ago

1.9.5

2 years ago

1.9.4

2 years ago

1.9.3

2 years ago

1.9.2

2 years ago

1.8.9

2 years ago

1.8.8

2 years ago

1.8.7

2 years ago

1.8.6

2 years ago

1.7.9

2 years ago

1.8.2

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.8.5

2 years ago

1.8.4

2 years ago

1.8.3

2 years ago

1.7.8

2 years ago

1.7.7

2 years ago

1.7.6

2 years ago

1.7.5

2 years ago

1.7.4

2 years ago

1.7.3

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.9

3 years ago

1.6.9

3 years ago

1.6.8

3 years ago

1.6.7

3 years ago

1.6.6

3 years ago

1.6.5

3 years ago

1.5.8

3 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.9

3 years ago

1.4.8

3 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.7

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.4.2

3 years ago

1.2.4

3 years ago

1.4.1

3 years ago

1.2.3

3 years ago

1.4.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.3.8

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.3.7

3 years ago

1.1.9

3 years ago

1.3.6

3 years ago

1.1.8

3 years ago

1.3.5

3 years ago

1.1.7

3 years ago

1.3.4

3 years ago

1.1.6

3 years ago

1.3.3

3 years ago

1.1.5

3 years ago

1.3.2

3 years ago

1.1.4

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.1.2

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.16

3 years ago

1.1.15

3 years ago

1.1.14

3 years ago

1.1.19

3 years ago

1.1.18

3 years ago

1.1.17

3 years ago

1.2.9

3 years ago

1.1.22

3 years ago

1.1.21

3 years ago

1.1.20

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago