Comments (3)
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.
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.
@wzup can you rewrite this and add example to README?
from express-paginate.
Related Issues (20)
- Example with EJS HOT 8
- implement "promises bluebird" HOT 2
- Something wrong with paginate.getArrayPages HOT 8
- Error: express-paginate: `limit` is not a number >= 0 HOT 1
- Documentation example errors HOT 2
- Update documentation HOT 1
- Page URLs wrong after the first page HOT 1
- Change references from jade to pug HOT 3
- How would I go about using this with mustache HOT 1
- How to send "skip" parameter? HOT 2
- Paginate only show first page HOT 2
- RethinkDB HOT 2
- how to set first and last link? HOT 2
- Handlebars paginate.href true gives weird value HOT 1
- Incompatibility with express 5 HOT 3
- Check integer HOT 1
- Wrong Offset
- Allow specifying minLimit
- @expressjs/triagers lack ability to add labels in express-paginate HOT 2
- how sort is working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-paginate.