TypeScript + node/express + mysql で、 CRUDの作成
index:
環境
TypeScript
node.js
npm
mysql
参考のコード
実装など
api、データ取得
https://github.com/kuc-arc-f/ts_express6_mysql/blob/master/routes/api.ts
/******************************** * *********************************/ router.get('/tasks_index', function(req: Request, res: Response, next: NextFunction ) { let connection :mysql.Connection; myDb.get_connection() .then((conn) => { connection = conn; return connection.query('SELECT * FROM tasks order by id desc'); }).then((results: any[]) => { // console.log(results ); results.forEach(result => { console.log(result.id ); }); connection.end(); var param = {"docs": results }; res.json(param); }); });
画面ejs
new
https://github.com/kuc-arc-f/ts_express6_mysql/blob/master/views/tasks/new.ejs
index
https://github.com/kuc-arc-f/ts_express6_mysql/blob/master/views/tasks/index.ejs
show
https://github.com/kuc-arc-f/ts_express6_mysql/blob/master/views/tasks/show.ejs
edit
https://github.com/kuc-arc-f/ts_express6_mysql/blob/master/views/tasks/edit.ejs