Skip to content

Instantly share code, notes, and snippets.

@eduardoromero
Last active July 22, 2019 00:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardoromero/f822a801cf83039f711c593998628014 to your computer and use it in GitHub Desktop.
Save eduardoromero/f822a801cf83039f711c593998628014 to your computer and use it in GitHub Desktop.
Getting data from RethinkDB
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