forked from halloffamezwx/zshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-db.js
31 lines (25 loc) · 877 Bytes
/
init-db.js
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
26
27
28
29
30
31
//初始化数据库 包括表和表数据 谨慎执行
const model = require('./middleware/model.js');
const fs = require('mz/fs');
var sequelize = model.sequelize;
(async () => {
await model.sync();
let fp = 'init-sql.sql';
var sqlBuffer = await fs.readFile(fp);
var sqlString = sqlBuffer.toString('utf-8');
var sqlStringArray = sqlString.split("\n");
for (let i = 0; i < sqlStringArray.length; i++) {
//console.log(sqlStringArray[i]);
if (sqlStringArray[i].trim() == '') {
continue;
}
await sequelize.query(sqlStringArray[i]);
}
process.exit(0);
})();
/* sequelize.query('select * from product').spread((results, metadata) => {
console.log(results);
});
sequelize.query('select * from product', { type: sequelize.QueryTypes.SELECT }).then(results => {
console.log(results);
}); */