• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

04_Go-1_04数据库数据表设计

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
一. API 设计
用户:上传、观看、下载、删除资源(视频)
评论:用户对视频可以进行评论
视频:被评论的视频与用户,三者的从属关系


1. 用户
创建/注册用户:
    URL: /user
    Method: POST
    SC:
        201:ok
        400500:

用户登录:
    URL: /user:/username
    Method: POST
    SC:
        200:ok
        400500:

获取用户基本信息:
    URL: /usr/username
    Method: GET 
    SC:
        200400401403500:

用户注销:
    URL: /user/username
    Method: DELETE
    SC:
        2044004014035002. 资源
List All videos
    URL: /user/:username/videos
    Method: GET
    SC:
        200
        400
        500

Get One Video
    URL: /user/:username/videos/:vid-id
    Method: GET
    SC: 
        200
        400
        500

Delete One Video
    URL: /user/:username/videos/:vid-id
    Method: DELETE
    SC:
        204
        400
        401
        403
        500


3. 评论
Show Comments
URL: /videos/:vid-id/comments
    Method: GET
    SC:
        200
        400
        500

Post A Comment
URL: /videos/:vid-id/comments
    Method: POST
    SC:
        201
        400
        500

Delete A Comment
URL: /videos/:vid-id/comment/:comment-id
    Method: DELETE
    SC:
        204
        400
        401
        403
        500


4. 数据表设计
4.1 users 表
CREATE TABLE `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `login_name` varchar(64) DEFAULT NULL,
  `pwd` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `login_name` (`login_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

> desc users;
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| id         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| login_name | varchar(64)      | YES  | UNI | NULL    |                |
| pwd        | text             | YES  |     | NULL    |                |
+------------+------------------+------+-----+---------+----------------+

4.2 video_info 表
CREATE TABLE `video_info` (
  `id` varchar(64) NOT NULL,
  `author_id` int(10) unsigned DEFAULT NULL,
  `name` text DEFAULT NULL,
  `display_ctime` text DEFAULT NULL,
  `create_time` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

> desc video_info;
+---------------+------------------+------+-----+---------------------+-------+
| Field         | Type             | Null | Key | Default             | Extra |
+---------------+------------------+------+-----+---------------------+-------+
| id            | varchar(64)      | NO   | PRI | NULL                |       |
| author_id     | int(10) unsigned | YES  |     | NULL                |       |
| name          | text             | YES  |     | NULL                |       |
| display_ctime | text             | YES  |     | NULL                |       |
| create_time   | datetime         | YES  |     | current_timestamp() |       |
+---------------+------------------+------+-----+---------------------+-------+

4.3 comments 表
CREATE TABLE `comments` (
  `id` varchar(64) NOT NULL,
  `video_id` varchar(64) DEFAULT NULL,
  `author_id` int(10) unsigned DEFAULT NULL,
  `content` text DEFAULT NULL,
  `time` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

> desc comments;
+-----------+------------------+------+-----+---------------------+-------+
| Field     | Type             | Null | Key | Default             | Extra |
+-----------+------------------+------+-----+---------------------+-------+
| id        | varchar(64)      | NO   | PRI | NULL                |       |
| video_id  | varchar(64)      | YES  |     | NULL                |       |
| author_id | int(10) unsigned | YES  |     | NULL                |       |
| content   | text             | YES  |     | NULL                |       |
| time      | datetime         | YES  |     | current_timestamp() |       |
+-----------+------------------+------+-----+---------------------+-------+

4.4 sessions 表
CREATE TABLE `sessions` (
  `session_id` char(64) NOT NULL,
  `TTL` tinytext DEFAULT NULL,
  `log_name` varchar(64) DEFAULT NULL,
  PRIMARY KEY (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
        
> desc sessions;
+------------+-------------+------+-----+---------+-------+
| Field      | Type        | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| session_id | char(64)    | NO   | PRI | NULL    |       |
| TTL        | tinytext    | YES  |     | NULL    |       |
| log_name   | varchar(64) | YES  |     | NULL    |       |
+------------+-------------+------+-----+---------+-------+

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Go语言介绍发布时间:2022-07-10
下一篇:
go笔记03发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap