diff --git "a/\347\216\213\351\224\246\345\206\233/express.zip" "b/\347\216\213\351\224\246\345\206\233/express.zip" new file mode 100644 index 0000000000000000000000000000000000000000..26c173a297826a1f503bd47cb7b109a3b5a7f9b1 Binary files /dev/null and "b/\347\216\213\351\224\246\345\206\233/express.zip" differ diff --git "a/\347\216\213\351\224\246\345\206\233/stu_tb/config.js" "b/\347\216\213\351\224\246\345\206\233/stu_tb/config.js" new file mode 100644 index 0000000000000000000000000000000000000000..e62baadcb0c110ec4074067ce2fa6700e620337d --- /dev/null +++ "b/\347\216\213\351\224\246\345\206\233/stu_tb/config.js" @@ -0,0 +1,7 @@ +module.exports={ + host:"localhost", + user:"root", + password:"wjj1929707670", + database:"student", + port:3306 +} \ No newline at end of file diff --git "a/\347\216\213\351\224\246\345\206\233/stu_tb/student.js" "b/\347\216\213\351\224\246\345\206\233/stu_tb/student.js" new file mode 100644 index 0000000000000000000000000000000000000000..a159746573cfd5182a37142f5ab0b260a4a11795 --- /dev/null +++ "b/\347\216\213\351\224\246\345\206\233/stu_tb/student.js" @@ -0,0 +1,68 @@ +//作业:创建一个学生表,里面有班级字段,里面最好有自己班上同学姓名,其它班级的姓名随机写,有个字段存储游戏的分值,先实现随机的数值写入,查询出各班级前三名的学生 +// tips:先要用npm 下载 sequelize和mysql2 +let con=require("./config"); +const { Sequelize, Model, DataTypes } = require('sequelize'); +const sequelize = new Sequelize(con.database, con.user, con.password, { + //申明下使用的数据库 + dialect: 'mysql', + host:con.host,//如果变量的key和value的变量一致,可以简写 + port: con.port, + logging: true,//日志 + timezone: '+08:00',//东八区 + define: { + timestamps: false,//默认会开启创建时间和修改时间 + underscored: true,//会把对象的属性名,由小驼峰转成下划线 + deletedAt:false, + } +}); + +class Student extends Model { } + +Student.init({ + // attributes + stu_id: { + type: DataTypes.INTEGER, + allowNull: false, + primaryKey: true, + autoIncrement:true, + }, + stu_class: { + type: DataTypes.STRING + // allowNull defaults to true + }, + stu_name: { + type: DataTypes.STRING + }, + score: { + type: DataTypes.BIGINT + }, + +}, { + sequelize, + modelName: 'stu_game', + // options + tableName: 'stu_game',//要关联表 +}); + + +//update +// async function update(){ +// await Student.update({ +// score: 45 +// },{ +// where:{score: null} +// }) +// } +// update() + + function getscoremax3(){ + let all= Student.findAll({ + order: [['score','DESC']], + limit:3 + + }) + all.then((all)=>{ + console.log(JSON.stringify(all,null,4) ); + }) +} +getscoremax3() diff --git "a/\347\216\213\351\224\246\345\206\233/stu_tb/student.sql" "b/\347\216\213\351\224\246\345\206\233/stu_tb/student.sql" new file mode 100644 index 0000000000000000000000000000000000000000..6342c8769fa84fc03fff2f8ae8dd6f2a76001a70 --- /dev/null +++ "b/\347\216\213\351\224\246\345\206\233/stu_tb/student.sql" @@ -0,0 +1,39 @@ +/* + Navicat Premium Data Transfer + + Source Server : Student + Source Server Type : MySQL + Source Server Version : 50737 + Source Host : localhost:3306 + Source Schema : student + + Target Server Type : MySQL + Target Server Version : 50737 + File Encoding : 65001 + + Date: 27/02/2023 17:40:41 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for stu_game +-- ---------------------------- +DROP TABLE IF EXISTS `stu_game`; +CREATE TABLE `stu_game` ( + `stu_id` int(11) NOT NULL AUTO_INCREMENT, + `stu_class` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `stu_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `score` bigint(20) UNSIGNED NULL DEFAULT NULL, + PRIMARY KEY (`stu_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of stu_game +-- ---------------------------- +INSERT INTO `stu_game` VALUES (1, '7班', 'wjj', NULL); +INSERT INTO `stu_game` VALUES (2, '7班', 'zm', NULL); +INSERT INTO `stu_game` VALUES (3, '2班', 'wwl', NULL); + +SET FOREIGN_KEY_CHECKS = 1;