Utilities
This file contains utilities for creating custom services. Utilities are available here; some documentation can be found below.
CSV Toolset
We provide a helper for parsing and loading CSV file into NetsBlox database to help development of new services. If your dataset is not in CSV but is easily convertible, you write a script to convert it to CSV to be able to take advantage of this toolset.
How
You can find this helper in the RPC utilities directory: $PROJECT_ROOT/src/server/rpc/procedures/utils
.
The interface to this helper accepts a few parameters:
Mongoose model: A mongoose model defined using
src/server/rpc/advancedStorage.js
- an options object:
url
- a direct url to the CSV filefilePath
- file system path to the CSV filerecParser
- a function that gets passed each record (or line in the input csv) for optional processing.
Sample
Here is a sample seed file for a service:
1#!/bin/env node
2
3// import the csv toolset
4const seeder = require('../utils/csv-toolset');
5
6// import the database model (Mongoose)
7const MyModel = require('./database');
8
9// prepare and convert the dataset
10
11const opts = {
12 url: undefined, // provide url or filePath
13 filePath: './myDataset.csv',
14 recParser: function(aRecord) { // optional
15 // process the record
16 return aRecord;
17 },
18};
19
20seeder(MyModel, opts);