mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
var router = require('express').Router();
|
|
var TYPES = require('tedious').TYPES;
|
|
|
|
/* GET task listing. */
|
|
router.get('/', function (req, res) {
|
|
|
|
req.query("select * from todo for json path")
|
|
.into(res, '[]');
|
|
|
|
});
|
|
|
|
/* GET single task. */
|
|
router.get('/:id', function (req, res) {
|
|
|
|
req.query("select * from todo where id = @id for json path, without_array_wrapper")
|
|
.param('id', req.params.id, TYPES.Int)
|
|
.into(res, '{}');
|
|
|
|
});
|
|
|
|
/* POST create task. */
|
|
router.post('/', function (req, res) {
|
|
|
|
req.query("exec createTodo @todo")
|
|
.param('todo', req.body, TYPES.NVarChar)
|
|
.exec(res);
|
|
|
|
});
|
|
|
|
/* PUT update task. */
|
|
router.put('/:id', function (req, res) {
|
|
|
|
req.query("exec updateTodo @id, @todo")
|
|
.param('id', req.params.id, TYPES.Int)
|
|
.param('todo', req.body, TYPES.NVarChar)
|
|
.exec(res);
|
|
|
|
});
|
|
|
|
/* DELETE single task. */
|
|
router.delete('/:id', function (req, res) {
|
|
|
|
req.query("delete from todo where id = @id")
|
|
.param('id', req.params.id, TYPES.Int)
|
|
.exec(res);
|
|
|
|
});
|
|
|
|
module.exports = router; |