Code Monkey home page Code Monkey logo

Comments (8)

mcollina avatar mcollina commented on June 27, 2024

Nice catch! :D May I ask you to submit a pull request?

from levelgraph.

pietercolpaert avatar pietercolpaert commented on June 27, 2024

Continuing on the discussion here: 86847a4#commitcomment-6691590

What if we implement a getStream which accepts as an option to start from a certain triple? That's a good way to paginate, yet you will not give a page=X, but now you will give a starttriple=SPO instead.

from levelgraph.

mcollina avatar mcollina commented on June 27, 2024

Yes, that was what I was thinking. It's a good way to go. Would you like to
be a contributor here? So we might work on this together.

from levelgraph.

pietercolpaert avatar pietercolpaert commented on June 27, 2024

Continuing in a new issue as this is getting off topic: #81

from levelgraph.

neonstalwart avatar neonstalwart commented on June 27, 2024

bump... was this ever fixed?

from levelgraph.

mcollina avatar mcollina commented on June 27, 2024

Definitely not, the whole 'limit + offset' thing is kind of broken if you read the whole discussion.

The right approach will be to start reading back from where it left, e.g. giving a startTriple parameter.

Anyway, @neonstalwart would you like to submit a PR on this issue? Maybe with @pietercolpaert fix + unit tests?

from levelgraph.

snowyu avatar snowyu commented on June 27, 2024

Yes, pagination using the last key info is right way. I've added the 'last' event
and next option to solve the stream pagination problem in level-subkey. Just reference:

var callbackStream = require('callback-stream')

var lastKey = null;
function nextPage(db, aLastKey, aPageSize, cb) {
  var stream = db.readStream({next: aLastKey, limit: aPageSize})
  stream.on('last', function(aLastKey){
    lastKey = aLastKey;
  });

  stream.pipe(callbackStream(function(err, data){
    cb(data, lastKey)
  }))

}

var pageNo = 1;
dataCallback = function(data, lastKey) {
    console.log("page:", pageNo);
    console.log(data);
    ++pageNo;
    if (lastKey) {
      nextPage(db, lastKey, 10, dataCallback);
    }
    else
      console.log("no more data");
}
nextPage(db, lastKey, 10, dataCallback);

from levelgraph.

BigBlueHat avatar BigBlueHat commented on June 27, 2024

👍 to removing offset entirely in favor of adding start or startTriple syntax.

Pretty limited pagination options atm...heh...

from levelgraph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.