Please help me.
Hey @smurali1717,
For your first question, what connector are you using?
This is for MySQL:
Using the datatype field/column option with MySQL
loopback-connector-mysql allows mapping of LoopBack model properties to MySQL columns using the 'mysql' property of the property definition. For example in /common/models/model.json
"locationId":{
"type":"String",
"required":true,
"length":20,
"mysql":
{
"columnName":"LOCATION_ID",
"dataType":"VARCHAR2",
"dataLength":20,
"nullable":"N"
}
}
You can also use the dataType column/property attribute to specify what MySQL column type to use for many loopback-datasource-juggler types. The following type-dataType combinations are supported:
integer
tinyint
smallint
mediumint
int
bigint
Source: https://docs.strongloop.com/display/public/LB/MySQL+connector
@smurali1717
How to introduce Property Alias name? for example, in post property name and my db property name may differ so in this cases how to handle (apart from any remote methods)
If you already have a table or schema in your database, you can use discoverAndBuildModels to map it to your lb model. Please check doc https://docs.strongloop.com/display/public/LB/Discovering+models+from+relational+databases for more details.
And if you have a different property name between lb and your database, you can specify the database_property_name in your model.json:
"lbName": {
"type": "string",
"mysql": {
"columnName": "mysqlName"
}
}
Please check this doc for details:
https://docs.strongloop.com/display/public/LB/Connecting+to+MySQL
I want to change the JSON result structure, without any custom methods. is it possible?
Sorry I am a little confused, how do you want to change the JSON result structure?
Apologies for not mentioned connector name. I am using DB2 connector. From DB2 connector is it possible. The same example throwing me an error when I tried to use it in DB2. Is it possible from DB2?
For example:
{
{
"firstname":"Murali",
"lastname":"Sankaran",
"address":"address information",
"age":31,
"propertyA":"some property A details",
"propertyB":"some property B details"
}
}
To change:
{
{
"name":{
"firstname":"Murali",
"lastname":"Sankaran"
},
"personalInformaiton":{
"address":"address information",
"age":31
},
"propertyDetails":{
"propertyA":"some property A details",
"propertyB":"some property B details"
}
}
}
Is there any easiest way to do it.
@smurali1717 we support property type to be Object, could you try like define an object property called name:
"name": {
"firstName": "my_first_name",
"lastName": "my_last_name"
}
I am closing issue here. Please feel free to reopen it if you have further questions.
Most helpful comment
@smurali1717
If you already have a table or schema in your database, you can use
discoverAndBuildModelsto map it to your lb model. Please check doc https://docs.strongloop.com/display/public/LB/Discovering+models+from+relational+databases for more details.And if you have a different property name between lb and your database, you can specify the database_property_name in your model.json:
Please check this doc for details:
https://docs.strongloop.com/display/public/LB/Connecting+to+MySQL
Sorry I am a little confused, how do you want to change the
JSON result structure?