Better handle discovery of nullable columns
This commit is contained in:
parent
f130b8c5fa
commit
f9caaafe37
|
@ -141,18 +141,28 @@ function mixinDiscovery(MySQL) {
|
|||
function queryColumns(owner, table) {
|
||||
var sql = null;
|
||||
if (owner) {
|
||||
sql = paginateSQL('SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName", data_type AS "dataType",'
|
||||
+ ' character_octet_length AS "dataLength", numeric_precision AS "dataPrecision", numeric_scale AS "dataScale", is_nullable AS "nullable"'
|
||||
+ ' FROM information_schema.columns'
|
||||
+ ' WHERE table_schema=\'' + owner + '\''
|
||||
+ (table ? ' AND table_name=\'' + table + '\'' : ''),
|
||||
'table_name, ordinal_position', {});
|
||||
sql = paginateSQL('SELECT table_schema AS "owner",' +
|
||||
' table_name AS "tableName", column_name AS "columnName",' +
|
||||
' data_type AS "dataType",' +
|
||||
' character_octet_length AS "dataLength",' +
|
||||
' numeric_precision AS "dataPrecision",' +
|
||||
' numeric_scale AS "dataScale",' +
|
||||
' is_nullable = \'YES\' AS "nullable"' +
|
||||
' FROM information_schema.columns' +
|
||||
' WHERE table_schema=\'' + owner + '\'' +
|
||||
(table ? ' AND table_name=\'' + table + '\'' : ''),
|
||||
'table_name, ordinal_position', {});
|
||||
} else {
|
||||
sql = paginateSQL('SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName", data_type AS "dataType",'
|
||||
+ ' character_octet_length AS "dataLength", numeric_precision AS "dataPrecision", numeric_scale AS "dataScale", is_nullable AS "nullable"'
|
||||
+ ' FROM information_schema.columns'
|
||||
+ (table ? ' WHERE table_name=\'' + table + '\'' : ''),
|
||||
'table_name, ordinal_position', {});
|
||||
sql = paginateSQL('SELECT table_schema AS "owner",' +
|
||||
' table_name AS "tableName", column_name AS "columnName",' +
|
||||
' data_type AS "dataType",' +
|
||||
' character_octet_length AS "dataLength",' +
|
||||
' numeric_precision AS "dataPrecision",' +
|
||||
' numeric_scale AS "dataScale",' +
|
||||
' is_nullable = \'YES\' AS "nullable"' +
|
||||
' FROM information_schema.columns' +
|
||||
(table ? ' WHERE table_name=\'' + table + '\'' : ''),
|
||||
'table_name, ordinal_position', {});
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
@ -178,6 +188,7 @@ function mixinDiscovery(MySQL) {
|
|||
} else {
|
||||
results.map(function (r) {
|
||||
r.type = mysqlDataTypeToJSONType(r.dataType, r.dataLength);
|
||||
r.nullable = r.nullable ? 'Y' : 'N';
|
||||
});
|
||||
cb(err, results);
|
||||
}
|
||||
|
|
|
@ -200,12 +200,14 @@ describe('Discover LDL schema from a table', function () {
|
|||
assert(schema.options.mysql.schema === 'STRONGLOOP');
|
||||
assert(schema.options.mysql.table === 'INVENTORY');
|
||||
assert(schema.properties.productId);
|
||||
assert(schema.properties.productId.required);
|
||||
assert(schema.properties.productId.type === 'String');
|
||||
assert(schema.properties.productId.mysql.columnName === 'PRODUCT_ID');
|
||||
assert(schema.properties.locationId);
|
||||
assert(schema.properties.locationId.type === 'String');
|
||||
assert(schema.properties.locationId.mysql.columnName === 'LOCATION_ID');
|
||||
assert(schema.properties.available);
|
||||
assert(schema.properties.available.required === false);
|
||||
assert(schema.properties.available.type === 'Number');
|
||||
assert(schema.properties.total);
|
||||
assert(schema.properties.total.type === 'Number');
|
||||
|
|
Loading…
Reference in New Issue