0.1.4 • Published 4 years ago

loopback-import-export-mixin v0.1.4

Weekly downloads
12
License
ISC
Repository
github
Last release
4 years ago

loopback-import-export-mixin

Loopback mixin for bulk importing and exporting models

Status

Build 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());

alt text

LICENSE

Apache License