1 |
|
2 |
|
3 |
|
4 | const fs = require('fs');
|
5 | const func = require('../common/func');
|
6 |
|
7 | module.exports = function (tables, markdown) {
|
8 | var text = '# 数据库文档\n\n';
|
9 | const tableHeader =
|
10 | '|字段|类型|允许为空|是否主键|是否自增|说明|\n' +
|
11 | '|:---:|:---:|:---:|:---:|:---:|:---:|\n';
|
12 |
|
13 |
|
14 | var tablesArray = Object.keys(tables);
|
15 | func.quickSort(tablesArray, 0, tablesArray.length - 1);
|
16 |
|
17 |
|
18 | for (var table of tablesArray) {
|
19 | text = text + '## ' + table + '\n';
|
20 | text += tableHeader;
|
21 |
|
22 | for (var field in tables[table]) {
|
23 | text = text + '|' + field;
|
24 |
|
25 | var property = tables[table][field];
|
26 | text = text +
|
27 | '|' + func.typeTransform(property.type) +
|
28 | '|' + func.spaceToFalse(property.allowNull) +
|
29 | '|' + func.spaceToFalse(property.primaryKey) +
|
30 | '|' + func.spaceToFalse(property.autoIncrement) +
|
31 | '|' + func.spaceToFalse(property.description);
|
32 | text += '|\n'
|
33 | }
|
34 | text += '\n'
|
35 | }
|
36 |
|
37 |
|
38 | fs.writeFile(markdown.path + markdown.file , text, function (err) {
|
39 | if (err) throw err;
|
40 | console.log('It\'s saved!');
|
41 | return true;
|
42 | });
|
43 | };
|
44 |
|
45 |
|