Closed FredLackeyOfficial closed 7 years ago
@FredLackeyOfficial Thank you for bringing this up. What you are seeing is the default behaviour as of v3.0.0 of this connector. If you would like your CHAR(1)
column to be treated as a String
instead of a Boolean
LoopBack type, then you need to set treatCHAR1AsString
to true as part of your options to discoverSchema()
like so:
module.exports = function(app) {
var db = app.datasources.mysqlDs;
var tableName = 'charTable';
db.discoverSchema(tableName, { visited: {}, associations: true, treatCHAR1AsString: true},
function(err, schema) {
if (err) throw err;
console.log('char(1) col >>', JSON.stringify(schema.properties.charcol));
});
};
Result:
Web server listening at: http://localhost:3000
Browse your REST API at http://localhost:3000/explorer
char(1) col >> {"type":"String","required":false,"length":1,"precision":null,"scale":null,"mysql":{"columnName":"charcol","dataType":"char","dataLength":1,"dataPrecision":null,"dataScale":null,"nullable":"Y"}}
I have updated our README to reflect the flags introduced then for CHAR(1)
, BIT(1)
, and TINYINT(1)
columns.
Interesting. I'd love to understand the logic behind switching the data types from char(1) to boolean as a default.
You can have a look at #232.
The following JSON is the result of performing...
The following snippet was taken from the resulting JSON file. Notice the type ID is Boolean where the MySQL type remains char(1)...
darwin x64 6.11.1 loopback-example-database@2.0.0 /Users/flackey/Source/GitHub/StrongLoop/loopback-example-database ├── loopback@3.9.0 ├── loopback-boot@2.25.0 ├── loopback-component-explorer@2.7.0 ├── loopback-connector-mongodb@1.18.1 ├── loopback-connector-mysql@5.0.0