使用datasource.createModel(schema_v1.name,schema_v1.properties,schema_v1.options)... - 方法时,LoopBack在数据库中使用指定的field-datalength创建相应的模型。
但是在检索创建的模型时,field-datalength完全不同(尽管在数据库中是正确的)。
示例:
var schema_v1 =
{
"name": "CustomerTest",
"options": {
"idInjection": false,
"mysql": {
"schema": "LOOPBACK",
"table": "CUSTOMER_TEST"
}
},
"properties": {
"id": {
"type": "String",
"length": 20,
"id": 1
},
"email": {
"type": "String",
"required": false,
"length": 150
}
}
};
创建模型并检索它的属性后,属性的数据长度肯定是错误的。
datasource.createModel(schema_v1.name, schema_v1.properties, schema_v1.options);
datasource.automigrate(function () {
datasource.discoverModelProperties('CUSTOMER_TEST', function (err, props) {
if (err) {
console.log(err);
}
console.log(props);
});
});
输出:(使用datalength 150创建...使用datalength 450检索)
{
owner: 'aloop',
tableName: 'customer_test',
columnName: 'email',
dataType: 'varchar',
dataLength: 450,
dataPrecision: null,
dataScale: null,
nullable: 'YES',
type: 'String'
}
这是一个Bug - 可能是 - LoopBack mySql连接器?有任何想法吗?提前谢谢。
更新25.09.2014 @Raymond
我设置" DEBUG = ..." -property(按照您的建议)并使用" slc run"运行节点应用程序。
以下是输出:
supervisor running without clustering (unsupervised)
loopback:connector:mysql Settings: {"host":"127.0.0.1","port":3306,"database":"strongloop","username":"root","password":"","name":"mySql","connector":"mysql","debug":false,"collation":"utf8_general_ci","charset":"utf8","supportBigNumbers":false,"timezone":"local"
} +0ms
loopback:connector:mysql Settings: {"connector":{},"host":"127.0.0.1","port":3306,"database":"janushkaloop","username":"root","password":"","name":"mySql3","debug":false,"collation":"utf8_general_ci","charset":"utf8","supportBigNumbers":false,"timezone":"local"}
+1s
loopback:connector:mysql SQL: DROP TABLE IF EXISTS `CUSTOMER_TEST` +3ms
Browse your REST API at http://localhost:3000/explorer
Web server listening at: http://localhost:3000/
loopback:connector:mysql Data: +87ms { fieldCount: 0,
affectedRows: 0,
insertId: 0,
serverStatus: 2,
warningCount: 0,
message: '',
protocol41: true,
changedRows: 0 }
loopback:connector:mysql SQL: CREATE TABLE `CUSTOMER_TEST` (
`id` VARCHAR(20) NOT NULL PRIMARY KEY,
`name` VARCHAR(40) NULL,
`AMAIL` VARCHAR(150) NULL,
`age` INT(11) NULL
) +4ms
loopback:connector:mysql Data: +49ms { fieldCount: 0,
affectedRows: 0,
insertId: 0,
serverStatus: 2,
warningCount: 0,
message: '',
protocol41: true,
changedRows: 0 }
loopback:connector:mysql SQL: 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='JANUSHKALOOP' AND table_name='CUSTOMER_TEST' +1ms
loopback:connector:mysql Data: +52ms [ { owner: 'janushkaloop',
tableName: 'customer_test',
columnName: 'id',
dataType: 'varchar',
dataLength: 60,
dataPrecision: null,
dataScale: null,
nullable: 'NO' },
{ owner: 'janushkaloop',
tableName: 'customer_test',
columnName: 'name',
dataType: 'varchar',
dataLength: 120,
dataPrecision: null,
dataScale: null,
nullable: 'YES' },
{ owner: 'janushkaloop',
tableName: 'customer_test',
columnName: 'AMAIL',
dataType: 'varchar',
dataLength: 450,
dataPrecision: null,
dataScale: null,
nullable: 'YES' },
{ owner: 'janushkaloop',
tableName: 'customer_test',
columnName: 'age',
dataType: 'int',
dataLength: null,
dataPrecision: 10,
dataScale: 0,
nullable: 'YES' } ]
[ { owner: 'janushkaloop',
tableName: 'customer_test',
columnName: 'id',
dataType: 'varchar',
dataLength: 60,
dataPrecision: null,
dataScale: null,
nullable: 'NO',
type: 'String' },
{ owner: 'janushkaloop',
tableName: 'customer_test',
columnName: 'name',
dataType: 'varchar',
dataLength: 120,
dataPrecision: null,
dataScale: null,
nullable: 'YES',
type: 'String' },
{ owner: 'janushkaloop',
tableName: 'customer_test',
columnName: 'AMAIL',
dataType: 'varchar',
dataLength: 450,
dataPrecision: null,
dataScale: null,
nullable: 'YES',
type: 'String' },
{ owner: 'janushkaloop',
tableName: 'customer_test',
columnName: 'age',
dataType: 'int',
dataLength: null,
dataPrecision: 10,
dataScale: 0,
nullable: 'YES',
type: 'Number' } ]