router.put('/:id', (req,res) => { db('todo').where({ id: req.params.id}).update( { title: req.body.title || null, is_done: req.body.is_done || null }).returning('*').then(data => { res.send(data) }) //SELECT * FROM todo WHERE id = ourId })
all(callback) { db('options').asCallback((error, options) => { if (error) { console.error(error.message); callback(false, error.message, options); } else { callback(true, '', options); } }); }
updateViewCounter(id) { db('pages') .where('id', id) .update({ view: db.raw('view + 1') }) .then(); }
//get one cat by ID from db function getOne(id) { return db("cats") .where({ id }) .first(); }
router.delete('/:id', (req,res) => { db('todo').where({id: req.params.id}).del().then(() => { res.json({sucess: true}) }) })
app.put('/image',(req,res) => { const { id } = req.body; db('users').where('id','=',id) .increment('entries',1) .returning('entries') .then(entries => { res.json(entries[0]); }) .catch(err => res.status(400).json('Unable to get entries')) })
static all(callback) { db('users') .select() .asCallback((error, users) => { if (error) { console.error(error.message); callback(false, error.message, users); } else { callback(true, '', users); } }); }
directlyLoadPage(link, callback) { db('pages') .where('link', link) .then(value => { if (value.length !== 0) callback(value[0].converted_content); }) .catch(reason => { console.error(reason); }); }
//edit cat (cat data here includes everything we need to edit). Tip: you need the ID of cat to update otherwise //we have no idea which cat we're updating. function editOne(cat) { return db("cats") .where({ id: cat.id }) // find the cat to update .update({ name: cat.name, location: cat.location, age: cat.age }) //change the cat info to the new stuff .then(data => { return db("cats").where({ id: cat.id }); //return the cat we updated }); }
router.patch('/:id', function(req, res) { db('todo').where({id: req.params.id}).update(req.body).returning('*').then(function(data) { res.send(data); }); console.log(req.params.id); });
router.get('/:id', (req,res) => { db('todo').where({id: req.params.id}).select().then(data => { res.send(data) }) })
function findUser(body) { return db('users') .where({ username: body.username }) .first(); }
getByPageId(id, callback) { db('comments') .where('page_id', id) .asCallback((error, data) => { if (error) { console.error(error.message); callback(false, error.message, undefined); } else { callback(true, '', data); } }); }
router.put('/:id', function(req, res) { db('todo').where({id: req.params.id}).update({ title: req.body.title || null, is_done: req.body.is_done || false }).returning('*').then(function(data) { res.send(data); }); console.log(req.params.id); // UPDATE table_name SET title='', is_done='' WHERE id = '' });
static getById(id, callback) { db('users') .where('id', id) .asCallback((error, data) => { if (error) { console.error(error.message); callback(false, error.message, undefined); } else { callback(true, '', data[0]); } }); }