# 初始化项目
# 表结构
# event_info
日历视角和时间四象限中的每一项事项
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for event_info
-- ----------------------------
DROP TABLE IF EXISTS `event_info`;
CREATE TABLE `event_info` (
`id` int NOT NULL AUTO_INCREMENT,
`title` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`description` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`is_done` tinyint NOT NULL DEFAULT '0' COMMENT '0 未完成 1 已完成',
`priority` enum('4','3','2','1') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '1' COMMENT '事件优先级',
`start_time` date NOT NULL,
`end_time` date NOT NULL,
`create_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
`update_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`delete_time` timestamp(6) NULL DEFAULT NULL,
`user_id` int DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_a374c5adbd24063d1e956a5d791` (`user_id`),
CONSTRAINT `FK_a374c5adbd24063d1e956a5d791` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=127 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SET FOREIGN_KEY_CHECKS = 1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# folder_info
待办箱中的清单
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for folder_info
-- ----------------------------
DROP TABLE IF EXISTS `folder_info`;
CREATE TABLE `folder_info` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(20) COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件夹名称',
`create_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
`update_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`delete_time` timestamp(6) NULL DEFAULT NULL,
`user_id` int DEFAULT NULL,
`sort_index` int NOT NULL COMMENT '展示顺序',
PRIMARY KEY (`id`),
KEY `FK_105bfaadf4b81849c56f49e6981` (`user_id`),
CONSTRAINT `FK_105bfaadf4b81849c56f49e6981` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SET FOREIGN_KEY_CHECKS = 1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# todo_info
待办箱中的清单中的每一项事项
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for todo_info
-- ----------------------------
DROP TABLE IF EXISTS `todo_info`;
CREATE TABLE `todo_info` (
`id` int NOT NULL AUTO_INCREMENT,
`title` varchar(20) COLLATE utf8mb4_general_ci NOT NULL,
`update_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`delete_time` timestamp(6) NULL DEFAULT NULL,
`create_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
`folder_id` int DEFAULT NULL,
`description` varchar(100) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`start_time` date DEFAULT NULL,
`end_time` date DEFAULT NULL,
`time` date NOT NULL,
`priority` enum('4','3','2','1') COLLATE utf8mb4_general_ci NOT NULL DEFAULT '1' COMMENT '事件优先级',
PRIMARY KEY (`id`),
KEY `FK_4028075aae7b5e68cca2331a1ed` (`folder_id`),
CONSTRAINT `FK_4028075aae7b5e68cca2331a1ed` FOREIGN KEY (`folder_id`) REFERENCES `folder_info` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=65 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SET FOREIGN_KEY_CHECKS = 1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# setting_info
设置中的偏好设置
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for setting_info
-- ----------------------------
DROP TABLE IF EXISTS `setting_info`;
CREATE TABLE `setting_info` (
`userId` int NOT NULL,
`start_week` enum('sunday','monday') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'monday' COMMENT '起始周设置',
`week_name` enum('starWeek','week') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'starWeek' COMMENT '周命名为星期还是周',
`create_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
`update_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`delete_time` timestamp(6) NULL DEFAULT NULL,
PRIMARY KEY (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SET FOREIGN_KEY_CHECKS = 1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# user
用户信息
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int NOT NULL AUTO_INCREMENT,
`password` varchar(255) NOT NULL,
`mobile` varchar(11) NOT NULL,
`avatar` varchar(255) DEFAULT NULL,
`username` varchar(20) NOT NULL,
`create_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
`update_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`is_lock` tinyint NOT NULL DEFAULT '0' COMMENT '0 锁定 1账户未锁定',
`is_cancel` tinyint NOT NULL DEFAULT '0' COMMENT '0 注销, 1 账户未注销',
`delete_time` timestamp(6) NULL DEFAULT NULL,
`gender` enum('0','1','-1') NOT NULL DEFAULT '-1' COMMENT '0 男, 1 女, -1 保密',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
SET FOREIGN_KEY_CHECKS = 1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 实体类
# 根据表结构生成实体类
通常来说,在工作环境中,大多数都是先建表后建类,在开发中也会有对应的工具可以通过表结构自动的生成实体类,比如midway
中的 typeorm_generator (opens new window),mybatis-plus
中的代码生成器
# 根据实体类自动同步表结构
当然也可以先写实体类,交给框架去同步表结构
将 synchronize
设置为 true
,即可自动同步,但不要在生产环境中开启
# 初始化 Midway 项目
npm init midway
1
midway
有多种技术方案可选,在这里我们选择 koa-v3
,创建一个纯 nodejs
应用。
使用这种方案,我们可以使用 IOC 依赖注入 + Class 的方式开发项目,并且后续也可以将其平滑的迁移至 Serverless
,更多详细介绍见文档 (opens new window)
另外,不得不说,midway 的官方文档其实挺好的,几乎你想要的都能找到
执行 npm run dev
命令,一个最最最基础的 midway
项目就跑起来了。