Last active
July 22, 2019 00:52
-
-
Save eduardoromero/f822a801cf83039f711c593998628014 to your computer and use it in GitHub Desktop.
Getting data from RethinkDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server.get('/', (req, res, next) => { | |
let _offset = parseInt(req.query.offset) || 0 | |
let _limit = parseInt(req.query.limit) || 10 | |
// max per page | |
if (_limit > 100) { | |
_limit = 100 | |
} | |
req.db.table('shares').filter({}).skip(_offset).limit(_limit) | |
.then((response) => { | |
res.status(200).send({ | |
data: response | |
}) | |
}) | |
.catch(error => res.status(500).send({error: error})) | |
}) | |
server.get('/:id', (req, res, next) => { | |
const id = req.params.id | |
req.db.table('shares').get(id) | |
.then((response) => { | |
res.status(200).json({ | |
data: response | |
}) | |
}) | |
.catch(error => res.status(500).send({error: error})) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment