2.4.0-10 • Published 8 years ago

@nxus/data-loader v2.4.0-10

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

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

2.4.0-10

8 years ago

2.4.0-9

8 years ago

2.4.0-8

8 years ago

2.4.0-7

8 years ago

2.4.0-6

8 years ago

2.4.0-5

8 years ago

2.4.0-4

8 years ago

2.4.0-3

8 years ago

2.4.0-2

8 years ago

2.4.0-1

8 years ago

2.4.0-0

8 years ago