当前位置:网站首页>Vue3+ts+node creates personal blog (database design)

Vue3+ts+node creates personal blog (database design)

2022-06-12 01:18:00 Tusi

The code of this project has been open source , Specific view :

The front-end engineering :vue3-ts-blog-frontend

Back end Engineering :express-blog-backend

Database initialization script : Official account Front end Sinan , Reply key “ Blog database script ”, Can get .

What should a blog system do , I believe everyone is very familiar with , Its core is nothing more than article classification A literary creation . And like label Comment on Leaving a message. communication Background management These functions , It's all icing on the cake .

To implement these functions , The most important thing is to sort out the relationship between various functions . When it comes to relationships , Naturally, it will be associated with relational databases .

Before designing the database , We need to clarify the relationship between entities first , I'll use E-R Figure or UML And other modeling languages .

But from the perspective of non professional database users like me , I think we can be informal , It doesn't have to be limited to E-R Figure or UML, You can also choose to use graphical presentation tools such as mind mapping . Because this is only a preliminary design stage .

As shown in the figure above , For my personal blog , I did a simple entity and entity relationship design .

Many to many relationship

Among them, the article table article Is the core , Consider that an article may be associated with multiple categories category Or tags tag, There will also be multiple articles under a category or label , So all my designs here are Many to many relationship , A relational table is used .

Relational tables do not involve many fields .

The two foreign keys designed in the relational table play a key role .

According to such a relation table , You can complete many to many relationships .

One-to-many relation

There are comments under the article , An article can have multiple comments , article article And comments comment The relationship is one to many , This is easy to understand .

For this kind of One to many Relationship , My design is to use a foreign key in the comment table article_id To make connections .

When you want to query the comments under an article , Can be based on conditions article_id Filter out the corresponding comment data .

SELECT * FROM comments WHERE article_id = 229;
 Copy code 

Child relationships

similarly , There will also be many responses under one comment , For reply , I designed it alone reply surface .comment and reply It's also a one to many relationship ,reply Table has comment_id Foreign keys are associated to comment surface .

In addition to responding to comments , You can also reply to a reply , Something like this :

And this seed level relationship , You just need one parent_id To take notes , according to parent_id A string of relationships , On the business side, we can get a reply tree .

Status field

Many businesses are inseparable from state maintenance , For example, the logical deletion of data , Publication of articles / Private treatment , Comment on / Review mechanism for replies , These all require some flag bits to describe the status , At the same time, some business interfaces are provided to maintain the status .

Summary

This article is about Vue3+TS+Node Create a personal blog ( Database design ), It mainly introduces some main ideas and concerns when I design the database for the blog system , Next, we will analyze some specific business implementations in more detail , Coming soon !

Series articles

Vue3+TS+Node Create a personal blog The series is as follows , Continuous updating , Welcome to ! Praise, focus on not getting lost !

原网站

版权声明
本文为[Tusi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202203011409534721.html