nv-db-fetch

1.0.0 • Public • Published

nv-db-fetch

  • fetch remote database

install

  • npm install nv-db-fetch

usage

  • const {init_iter,fetch,TMOUT} = require("nv-db-fetch");
  • init_iter(each_time_limit,total)
  • handler(self) {/.../}
  • fetch(handler,it);

examples:

const {init_iter,fetch} = require("nv-db-fetch");

//ready your remote-db
const AV = require('leancloud-storage');
const { Query, User } = AV;
const appId = "xxxxxxxxxxx"
const appKey =  "xxxxxxxxx"
const serverURL = "https://xxxxxxx"

const {sync_av_init} = require("./lean");
sync_av_init(AV,appId,appKey,serverURL);

var query = new AV.Query('gps_info');

//config
var it = init_iter(100,450);
it.query = query
it.each_tmout = 5000
it.total_tmout = 30000    

//write handler

function handler(self) {
    let it = self.args;     // iter  stored in self.args
    
    let query = it.query;
    query.ascending('createdAt');
    query.limit(it.limit);
    query.skip(it.si);
    let p = query.find();
    return(p);
}


//
var p = fetch(handler,it);
p.then(it=>{
    console.log(it.args.rslt.length)  // final result in it.args.rslt
}).catch(err=>{console.log(err)})

results

> it
{
  each_tmout: 5000,
  total_tmout: 30000,
  limit: 100,
  si: 450,
  real_count: 100,
  next_expected_count: 0,
  total: 450,
  lefted: 0,
  rslt: [....]
}
>
var rslt=[]
p.then(it=>{rslt = it.args.rslt});
> rslt.map(e=>e.attributes)
[
  {
    img_id: '5ccd76a60237d7006f261e80',
    exif_id: '5ccd76a80237d7006f261e89',
    gps_id: '5ccd76a8d3761600694d5579'
  },
  {
    img_id: '5ccd77b6ba39c80070d65e75',
    exif_id: '5ccd77b7d3761600694d60a7',
    gps_id: '5ccd77b7ba39c80070d65e84'
  },
  {
    img_id: '5ccd77cba91c930068c2a1f6',
    exif_id: '5ccd77cc17b54d0068cc412f',
    gps_id: '5ccd77cdd5de2b0074f9dfbb'
  },
  ....
]

LICENSE

  • ISC

Dependencies (3)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i nv-db-fetch

    Weekly Downloads

    0

    Version

    1.0.0

    License

    ISC

    Unpacked Size

    5.75 kB

    Total Files

    3

    Last publish

    Collaborators

    • ihgazni2