diff --git "a/\347\216\213\351\224\246\345\206\233/nodedb.zip" "b/\347\216\213\351\224\246\345\206\233/nodedb.zip" new file mode 100644 index 0000000000000000000000000000000000000000..a69fcd3f41d2bd73282502fa4363f38b6a34b86c Binary files /dev/null and "b/\347\216\213\351\224\246\345\206\233/nodedb.zip" differ diff --git "a/\347\216\213\351\224\246\345\206\233/proandorm/ormtest/dbmodule.js" "b/\347\216\213\351\224\246\345\206\233/proandorm/ormtest/dbmodule.js" new file mode 100644 index 0000000000000000000000000000000000000000..2a90583355e236b6e2163b0366042830fc13b2a8 --- /dev/null +++ "b/\347\216\213\351\224\246\345\206\233/proandorm/ormtest/dbmodule.js" @@ -0,0 +1,7 @@ +module.exports={ + host: "localhost", + user: "root", + password: "root", + port: 3306, + database: 'prodb' +} \ No newline at end of file diff --git "a/\347\216\213\351\224\246\345\206\233/proandorm/ormtest/usedbmodule.js" "b/\347\216\213\351\224\246\345\206\233/proandorm/ormtest/usedbmodule.js" new file mode 100644 index 0000000000000000000000000000000000000000..6865b167dda489c1eaac8aacaed363e26d6e0008 --- /dev/null +++ "b/\347\216\213\351\224\246\345\206\233/proandorm/ormtest/usedbmodule.js" @@ -0,0 +1,48 @@ +let conn = require("./dbmodule"); +//引入 +const { Sequelize, Model, DataTypes } = require('sequelize'); + +//初始化对象 +const sequelize = new Sequelize(conn.database, conn.user, conn.password, { + //申明下使用的数据库 + dialect: 'mysql', + host: conn.host, + port: conn.port, + logging: true,//日志 + timezone: '+08:00',//东八区 + define: { + timestamps: false, + } +}); + +//要不要创建表 +sequelize.sync({ force: false }) + +//创建对象,构建模型 +class Dis extends Model { } + +Dis.init({ + // attributes + dis_id: { + type: DataTypes.INTEGER, + allowNull: false, + primaryKey: true + }, + dis_user: { + type: DataTypes.STRING + // allowNull defaults to true + }, + dis_divide: { + type: DataTypes.STRING + } + +}, { + sequelize, + modelName: 'dis', + // options + tableName: 'dis',//要关联表 +}); + +Dis.findAll().then((data)=>{ + console.log(JSON.stringify(data, null, 4)); +}) \ No newline at end of file diff --git "a/\347\216\213\351\224\246\345\206\233/proandorm/promise/prodb.sql" "b/\347\216\213\351\224\246\345\206\233/proandorm/promise/prodb.sql" new file mode 100644 index 0000000000000000000000000000000000000000..8c53d6c415282079cd88713bc54c091803cdc029 --- /dev/null +++ "b/\347\216\213\351\224\246\345\206\233/proandorm/promise/prodb.sql" @@ -0,0 +1,38 @@ +/* + Navicat Premium Data Transfer + + Source Server : test + Source Server Type : MySQL + Source Server Version : 50737 + Source Host : localhost:3306 + Source Schema : prodb + + Target Server Type : MySQL + Target Server Version : 50737 + File Encoding : 65001 + + Date: 25/02/2023 11:00:40 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for dis +-- ---------------------------- +DROP TABLE IF EXISTS `dis`; +CREATE TABLE `dis` ( + `dis_id` int(11) NOT NULL AUTO_INCREMENT, + `dis_user` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `dis_divide` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + PRIMARY KEY (`dis_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of dis +-- ---------------------------- +INSERT INTO `dis` VALUES (1, '程晟', '二辩'); +INSERT INTO `dis` VALUES (2, 'wjj', '四辩'); +INSERT INTO `dis` VALUES (3, '行健', '三辩'); + +SET FOREIGN_KEY_CHECKS = 1; diff --git "a/\347\216\213\351\224\246\345\206\233/proandorm/promise/promisedb.js" "b/\347\216\213\351\224\246\345\206\233/proandorm/promise/promisedb.js" new file mode 100644 index 0000000000000000000000000000000000000000..4b9a636f3f32610721017a968775cff274c0d79d --- /dev/null +++ "b/\347\216\213\351\224\246\345\206\233/proandorm/promise/promisedb.js" @@ -0,0 +1,10 @@ +// 作业:第一个能不能使用promise的异步函数,封装下数据库的查询, +//二 把sequelize 配置完成,至少能查询一个表去看看sequelize的文档 +let prodb=require("./promodule"); +let readsql="SELECT * FROM dis"; +prodb.read(readsql).then((data)=>{ + console.log(data); +}).catch((error)=>{ + throw error; +}) +prodb.dbend(); diff --git "a/\347\216\213\351\224\246\345\206\233/proandorm/promise/promodule.js" "b/\347\216\213\351\224\246\345\206\233/proandorm/promise/promodule.js" new file mode 100644 index 0000000000000000000000000000000000000000..2e43e210597e5f1d3315dcce282ca8feac30eba4 --- /dev/null +++ "b/\347\216\213\351\224\246\345\206\233/proandorm/promise/promodule.js" @@ -0,0 +1,30 @@ +// 作业:第一个能不能使用promise的异步函数,封装下数据库的查询, +let mysql = require("mysql"); +let conn = mysql.createConnection({ + host: "localhost", + user: "root", + password: "root", + database: "prodb" +}) + +const { rootCertificates } = require("tls"); +module.exports = { + read: function (readsql) { + return new Promise((resolve, reject) => { + conn.connect((error) => { + if (error) { + throw error; + } + }) + + conn.query(readsql, (error, data) => { + resolve(data); + reject(error); + }) + + }) + }, + dbend: function () { + conn.end() + } +} \ No newline at end of file