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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #!/bin/env node
// import the csv toolset
const seeder = require('../utils/csv-toolset');
// import the database model (Mongoose)
const MyModel = require('./database');
// prepare and convert the dataset
const opts = {
url: undefined, // provide url or filePath
filePath: './myDataset.csv',
recParser: function(aRecord) { // optional
// process the record
return aRecord;
},
};
seeder(MyModel, opts);
|