loopback-import-export-mixin
v0.1.4
Published
Loopback mixin for bulk importing and exporting models
Downloads
9
Maintainers
Readme
loopback-import-export-mixin
Loopback mixin for bulk importing and exporting models
Status
Installation:
npm install --save loopback-import-export-mixin
Setup
SERVER CONFIG
Add the mixins
property to your server/model-config.json
:
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"../node_modules/loopback-import-export-mixin/src",
"../common/mixins"
]
}
}
MODEL CONFIG
To use with your Models add the mixins
attribute to the definition object of your model config.
{
"name": "Widget",
"properties": {
"name": {
"type": "string"
}
},
"mixins": {
"ImportExport" : {"export": {}}
}
}
Modify/Format your headers and rows before you export
{
"name": "Widget",
"properties": {
"name": {
"type": "string"
}
},
"mixins": {
"ImportExport": {
"export": {
"formatHeaders": "funcToFormatHeaders", // Optional
"formatRow": "funcToFormatRecord" // Optional
}
}
}
}
Then defined the function implemenation in your .js for Example to make all headers upper case. define the funciton as below
ModelName.funcToFormatHeaders = row=>row.map(r=>r.toUpperCase());