TypeScript + node/express + sequelize CRUDの作成
index:
環境
TypeScript
node.js
npm
sequelize
mysql
参考のコード
手順
・表の作成
https://github.com/kuc-arc-f/ts_sequelize1/blob/master/database/tasks.sql
npm install
・tscコンパイル
npm run build
( 開発する場合 、npm run watch )
・express 起動
npm start
実装など
api、データ取得
https://github.com/kuc-arc-f/ts_sequelize1/blob/master/routes/api.ts
router.get('/tasks_index', function(req: Request, res: Response, next: NextFunction ) { models.Task.findAll({ order: [ ['id', 'DESC'], ], }).then((result:any) => { var items = result items.forEach( function (item: any[]) { // console.log( item); }); var param = {"result": result}; res.json(param); }); });
画面ejs
new
https://github.com/kuc-arc-f/ts_sequelize1/blob/master/views/tasks/new.ejs
index
https://github.com/kuc-arc-f/ts_sequelize1/blob/master/views/tasks/index.ejs
show
https://github.com/kuc-arc-f/ts_sequelize1/blob/master/views/tasks/show.ejs
edit
https://github.com/kuc-arc-f/ts_sequelize1/blob/master/views/tasks/edit.ejs