Node.js 筆記(三)Sequelize Auto
上一篇文章中,Node.js 筆記(二)Sequelize (ORM Framework),我們可以看到如果models
資料夾中所有的model需要自己打那會需要花很長的時間。
所以今天要跟大家介紹可以自動產生的工具Sequelize Auto。
Quick Start
安裝
sequelize-auto
1
$ npm install -g sequelize-auto
執行產生
1
2
3
4
5$ sequelize-auto -o "./models" -d nodejs -h localhost -u root -p 3306 -x 1qaz2wsx -e mysql
Executing (default): SHOW TABLES;
Executing (default): SELECT K.CONSTRAINT_NAME as constraint_name , K.CONSTRAINT_SCHEMA as source_schema , K.TABLE_SCHEMA as source_table , K.COLUMN_NAME as source_column , K.REFERENCED_TABLE_SCHEMA AS target_schema , K.REFERENCED_TABLE_NAME AS target_table , K.REFERENCED_COLUMN_NAME AS target_column , C.extra , C.COLUMN_KEY AS column_key FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS K LEFT JOIN INFORMATION_SCHEMA.COLUMNS AS C ON C.TABLE_NAME = K.TABLE_NAME AND C.COLUMN_NAME = K.COLUMN_NAME WHERE K.TABLE_NAME = 'ADM_USER' AND K.CONSTRAINT_SCHEMA = 'nodejs';
Executing (default): DESCRIBE `ADM_USER`;
Done!
一開始因為我的
mysql
是8.0
以上的版本,在執行的時候出現了這個錯誤Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
。解決方法是登入
mysql
後輸入下面兩個指令:
%為
user的
host,查詢方式為
select user,host from user;`
1
2 mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '1qaz2wsx';
mysql> flush privileges;
驗證
今天就先介紹到這邊,有問題請再跟我說。
Donate
謝謝您的支持與鼓勵