不要怂,就是干,撸起袖子干!

Commit e10c3309 by Jan Aagaard Meier

Proper handling on UNSIGNED, BINARY and ZEROFILL in combi with length for sqlite

1 parent 59ba0b7c
Showing with 17 additions and 9 deletions
......@@ -55,8 +55,7 @@ module.exports = (function() {
return Utils._.includes(definition, 'PRIMARY KEY')
}).length > 1)
, attrStr = []
, endParen
, modifierLastIndex = -1
for (var attr in attributes) {
if (attributes.hasOwnProperty(attr)) {
......@@ -66,14 +65,23 @@ module.exports = (function() {
dataType = dataType.replace(/BIGINT/, 'INTEGER')
}
if ((endParen = dataType.indexOf(')')) !== -1 && endParen !== (dataType.length - 1)) {
// Move the length to the end of the string, as required by SQLite (needed for things like INTEGER(5) UNSIGNED -> INTEGER UNSIGNED(5))
var match = dataType.match(/\(\s*\d+(\s*,\s*\d)?\s*\)/)
if (match) {
match = match[0]
// SQLite thinks that certain modifiers should come before the length declaration,
// whereas other dialects want them after, see http://www.sqlite.org/lang_createtable.html.
// Start by finding the index of the last of the modifiers
['UNSIGNED', 'BINARY', 'ZEROFILL'].forEach(function (modifier) {
var tmpIndex = dataType.indexOf(modifier)
dataType = dataType.replace(match, '')
dataType += match
if (tmpIndex > modifierLastIndex) {
modifierLastIndex = tmpIndex + modifier.length
}
})
if (modifierLastIndex) {
// If a modifier was found, and a lenght declaration is given before the modifier, move the length
var length = dataType.match(/\(\s*\d+(\s*,\s*\d)?\s*\)/)
if (length && length.index < modifierLastIndex) {
dataType = dataType.replace(length[0], '')
dataType = Utils._.insert(dataType, modifierLastIndex, length[0])
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!