在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:7kmCo/koa-example开源软件地址:https://github.com/7kmCo/koa-example开源编程语言:JavaScript 66.3%开源软件介绍:Koa example/boilerplateThis repository demonstrates the usage of Sequelize within an Koa application. Starting AppFirst of all, don't forget to edit
This will start the application and create database tables. Just open http://localhost:3000. Sequelize SetupNow we will install all sequelize related modules. # install ORM , CLI and SQLite dialect
npm install --save sequelize sequelize-cli mysql2
# generate models
node_modules/.bin/sequelize init
node_modules/.bin/sequelize model:generate --name User --attributes firstName:string,lastName:string,email:string AuthenticationThere is several authentication strategies available. You can use which one you want and remove those you don't want. Available strategies:
For routes you want to be accessable only by authenticated users, router.get('/authenticated-route', authenticated(), async (ctx, next) => {
ctx.body = 'You are logged in'
}) Authenticated middleware is in Database RelationshipsFor demonstrating ORM relationship, Post model created. The relationship is between users and posts like" Post.belongsTo(User, {as: 'Author'}) You can find examples of relationship when creating new post, which each post will be associated to a user and also in route |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论