Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can i add table comment or column comment to SQL file? Model Documentation can use? #5

Open
lexyuan opened this issue Mar 9, 2017 · 4 comments

Comments

@lexyuan
Copy link

lexyuan commented Mar 9, 2017

No description provided.

@LucianoZu
Copy link

Please take a look to my pull request

@miqiang1986
Copy link

How to use it offline on mac? Which directory should I deposit in?

@LucianoZu
Copy link

LucianoZu commented Nov 28, 2018 via email

@cqghb
Copy link

cqghb commented Mar 7, 2024

将表注释、字段注释导出的代码:
导出表注释:
修改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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants