Giter VIP home page Giter VIP logo

Comments (3)

niftylettuce avatar niftylettuce commented on April 28, 2024

Use knex package (or another package that lets you write SQL queries) from NPM and connect it to your MySQL server.

Then write a query using knex (or your alternative) to paginate some data from your DB.

var start = (req.query.page - 1) * req.query.limit;
var end = (req.query.page * req.query.limit) - 1;
var query = 'SELECT * FROM some_table_name LIMIT ' + start + ',' + end;

(there are more efficient ways to write this SQL query, but this is just a simple example)

You just hook in the express-paginate middleware, then write normal SQL queries, and for your limit and offset numbers use the provided req.query.limit and req.query.page values (see the Readme).

Does this help @javabala?

from express-paginate.

wzup avatar wzup commented on April 28, 2024

@niftylettuce

Are you sure you wrote correct example?
end is actually a limit and it is normally a fixed value. Like only 10, 15, 20, so on records. So

LIMIT 20, 10

actually means: I need just 10 records starting from 20th.

And in your example end is not a fixed value. It is increased with every page.
If your goal is to return only 10 records every time (that is limit is 10), then by your example you get this:

(page 1): LIMIT 0, 9 // returns 9 records. starting from 0th
(page 2): LIMIT 10, 19 // returns 19 records, starting from 10th
(page 3): LIMIT 20, 29 // returns 29 records, starting from 20th

Every time your limit value is increased. Hence it is not a limit in its initial sense.

from express-paginate.

niftylettuce avatar niftylettuce commented on April 28, 2024

@wzup can you rewrite this and add example to README?

from express-paginate.

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.