Socket
Socket
Sign inDemoInstall

@nxus/data-loader

Package Overview
Dependencies
427
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @nxus/data-loader

Data format parsers and loaders for nxus


Version published
Maintainers
3
Install size
4.32 MB
Created

Readme

Source

DataLoader

src/index.js:43-183

Import file contents as arrays of objects

Installation

npm install @nxus/data-loader --save

Options

All responses accept an options argument, in addition to any parser-specific options you can indicate:

  • mapping: object of {field: newField} name mappings
  • identityFields: for importing to models, array of fields to be used for createOrUpdate query

Events

You can modify the records during import with the following specific events:

  • records.type: e.g. app.get('data-loader').after('records.csv', (results) => {})
  • record.type: e.g. app.get('data-loader).after('record.csv', (one) => {})
  • models.identity: e.g. app.get('data-loader').after('models.user', (results) => {})
  • model.identity: e.g. app.get('data-loader).after('model.user', (user) => {})

record_ events occur after parsing and name mapping model_ events occur after record events and before models are created/updated.

API

src/index.js:32-32

Import file contents as arrays of objects

Installation

npm install @nxus/data-loader --save

Options

All responses accept an options argument, in addition to any parser-specific options you can indicate:

  • mapping: object of {field: newField} name mappings
  • identityFields: for importing to models, array of fields to be used for createOrUpdate query
  • truncate: for importing to models, true/false for deleting existing collection data before import. Ignored if identityFields is provided.
  • strict: defaults to true. Only import columns/data that matches the attribute names for the model. Set to false to import everything.
Events

You can modify the records during import with the following specific events:

  • records.type: e.g. app.get('data-loader').after('records.csv', (results) => {})
  • record.type: e.g. app.get('data-loader).after('record.csv', (one) => {})
  • models.identity: e.g. app.get('data-loader').after('models.user', (results) => {})
  • model.identity: e.g. app.get('data-loader).after('model.user', (user) => {})

record_ events occur after parsing and name mapping model_ events occur after record events and before models are created/updated.

API


export

src/JSONExporter.js:14-21

Stringify an array of results into JSON. Assumes top-level is array, unless opts.key is provided to wrap results in an object.

Parameters

export

src/index.js:112-116

Request formattted output based on type

Parameters

  • type string The type (e.g. 'html') of the output content
  • records [object] The records to export
  • opts object Options for the exporter context

Returns Promise String of formatted output

exporter

src/index.js:96-98

Provide an exporter for a particular type (file extension)

Parameters

  • type string The type (e.g. 'html') this exporter creates
  • handler function Function to receive (content, options) and return formatted output content

import

src/index.js:125-132

Request parsed results based on type

Parameters

  • type string The type (e.g. 'html') of the content
  • content string The contents to parse
  • opts object Options for the parser context

Returns Promise Array of parsed result objects

importFile

src/index.js:140-149

Request parsed results from a file path

Parameters

  • filename string The filename to read and parse
  • opts object Options for the parser context

Returns Promise Array of parsed result objects

importFileToModel

src/index.js:172-176

Import file contents to a model

Parameters

  • model string The identity of the model to populate
  • filename string The filename to read and parse
  • opts object Options for the parser context

Returns Promise Array of instances

importToModel

src/index.js:159-163

Import string contents to a model

Parameters

  • model string The identity of the model to populate
  • type string The type (e.g. 'html') of the content
  • content string The contents to parse
  • opts object Options for the parser context

Returns Promise Array of instances

parser

src/index.js:86-90

Provide a parser for a particular type (file extension)

Parameters

  • type string The type (e.g. 'html') this renderer should handle
  • handler function Function to receive (content, options) and return parsed array of result objects

parse

src/JSONParser.js:14-20

Parse JSON into an array of results. Assumes top-level is array, unless opts.key is provided to pick a top-level key from parsed object as results.

Parameters

FAQs

Last updated on 06 Jun 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc