staruml-ddl
staruml-ddl copied to clipboard
how can i add table comment or column comment to SQL file? Model Documentation can use?
Please take a look to my pull request
How to use it offline on mac? Which directory should I deposit in?
Hi, you can add rows comments writing in documentation field.
Unfortunately I didn't manage table comments.
It works only for oracle script generated feature.
I don't know how config it on Mac.
Luciano
Il giorno mer 28 nov 2018, 09:04 miqiang1986 [email protected] ha scritto:
How to use it offline on mac? Which directory should I deposit in?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/niklauslee/staruml-ddl/issues/5#issuecomment-442355233, or mute the thread https://github.com/notifications/unsubscribe-auth/AI3KTMbHi5Ua-PydG8UaiQDrB62KqwHJks5uzkOngaJpZM4MYP8H .
将表注释、字段注释导出的代码: 导出表注释: 修改ddl-generator.js 文件下的writeTable方法,见方法体中倒数第二句。 ` writeTable (codeWriter, elem, options) { var self = this var lines = [] var primaryKeys = [] var uniques = []
// Table
codeWriter.writeLine('CREATE TABLE ' + self.getId(elem.name, options) + ' (')
codeWriter.indent()
// Columns
elem.columns.forEach(function (col) {
if (col.primaryKey) {
primaryKeys.push(self.getId(col.name, options))
}
if (col.unique) {
uniques.push(self.getId(col.name, options))
}
lines.push(self.getColumnString(col, options))
})
// Primary Keys
if (primaryKeys.length > 0) {
lines.push('PRIMARY KEY (' + primaryKeys.join(', ') + ')')
}
// Uniques
if (uniques.length > 0) {
lines.push('UNIQUE (' + uniques.join(', ') + ')')
}
// Write lines
for (var i = 0, len = lines.length; i < len; i++) {
codeWriter.writeLine(lines[i] + (i < len - 1 ? ',' : ''))
}
codeWriter.outdent()
codeWriter.writeLine(');')
codeWriter.writeLine('alter table ' + tableName + ' comment \'' + elem.documentation +'\';') /* 将表注释导出 */
codeWriter.writeLine()
} `
字段注释导出: 修改ddl-generator.js 文件下的getColumnString方法,见方法体中最后一个if语句。
getColumnString (elem, options) { var self = this var line = self.getId(elem.name, options) var _type = elem.getTypeString() if (_type.trim().length === 0) { _type = 'INTEGER' } line += ' ' + _type if (elem.primaryKey || !elem.nullable) { line += ' NOT NULL' } /** 导出字段注释 start / if (elem.documentation) { line += ' comment '' + elem.documentation + ''' } / 导出字段注释 start **/ return line }