Chat App by using Nodejs, Graphql, Mysql

chat-app

This is a chat app by using Nodejs, GraphQL, MySQL

Build MySQL

Use Docker

建立密碼為 root 的 chat 資料庫
docker run --name classsed-chat-mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=chat -p 3306:3306 -d mysql:8.0

Modify the config/config.json "host": "0.0.0.0"to connect to the Docker container

透過 Terminal 用 root 帳號登入 chat 資料庫
docker exec -it classsed-chat-mysql mysql -u root -p chat

Added model (table)

Create a new model called User. There will be user.js in the models directory and .js files with date and time numbers in the migrations directory (both can be changed)

sequelize model:generate --name User --attributes username:string,email:string

Update to mysql, create table

sequelize db:migrate

Cancel the last migration (the DB data will be cleared)

sequelize db:migrate:undo
搭配 show tables; 查看上次建立的 table 會消失。
取消所有的migration
sequelize db:migrate:undo:all

Create a new model called Message. Used to record the content of the conversation, sender and recipient

sequelize model:generate --name Message --attributes content:string,uuid:uuid,from:string,to:string
sequelize db:migrate

Add two data

mysql> insert into `users` (`username`, `email`, `createdAt`, `updatedAt`) values ('bacon', 'bacon@mail.com', '2020-09-24 10:00:00', '2020-09-24 10:00:00');

mysql> insert into `users` (`username`, `email`, `createdAt`, `updatedAt`) values ('lynn', 'lynn@mail.com', '2020-09-24 11:00:00', '2020-09-24 11:00:00');

View the schema of a specific table

查看 users table 欄位
mysql> describes users;

Clear user table data

mysql> delete from users;

Download Details:

Author: baconYao

Source Code: https://github.com/baconYao/chat-app

#nodejs #javascript #node #graphql #mysql

Chat App by using Nodejs, Graphql, Mysql
10.90 GEEK