Skip to content

Instantly share code, notes, and snippets.

@lbrenman
Created August 13, 2016 02:04
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lbrenman/d399ebc340d8e813bf87275be4a5640d to your computer and use it in GitHub Desktop.
Arrow - How to Populate Your Arrow Builder Project With Data

How to Populate Your Arrow Builder Project With Data

Currently there is no means to import data into your Arrow Project. This is particularly important for ArrowDB projects but the technique can be applied to other back end data source (e.g. MySQL). This is also useful for creating temporary API's and providing mock data when the API is used.

The following is one way to accomplish this.

  1. You will need to have your data represented as JSON. If you have a CSV file, you can use CSV2JSON or similar
  2. Alternately, for mock data, you can use mockaroo or similar
  3. Use the same field names as your ArrowDB model's field names
  4. Save the JSON data to a file on your hard disk
  5. Create an Arrow Custom API
  6. Either add the JSON data as an array variable to your Custom API JS file (populateData.js) or convert your JSON file to JS and make the data an export.module variable (MOCK_DATA.js). Require this file in your custom API JS file (populateData2.js)
  7. When the custom API is called, loop through the data and programmatically create a model record:
Model.create(object, function(err, instance) {
      ...
});
  1. Call this custom API anytime you want to populate the data set
  2. Use the model APIs to perform other normal operations: FindAll, DeleteAll, ...
var Arrow = require('arrow');
var Model = Arrow.createModel('account', {
fields: {
Name: {
type: String
},
Type: {
type: String
},
Phone: {
type: String
}
},
connector: 'appc.arrowdb',
actions: [
'create',
'read',
'update',
'delete',
'deleteAll'
]
});
module.exports = Model;
module.exports = {
data: [
{"Name":"Demivee","Type":"Prospect","Phone":"1-(818)173-8443"},
{"Name":"Shufflester","Type":"Prospect","Phone":"93-(232)869-5557"},
{"Name":"Voonte","Type":"Customer","Phone":"62-(269)473-1186"},
{"Name":"Thoughtsphere","Type":"Prospect","Phone":"86-(902)994-3017"},
{"Name":"Zoonder","Type":"Customer","Phone":"1-(202)358-2758"},
{"Name":"Flashspan","Type":"Customer","Phone":"57-(126)114-4912"},
{"Name":"Yoveo","Type":"Customer","Phone":"593-(320)380-5127"},
{"Name":"Jabberstorm","Type":"Customer","Phone":"62-(637)263-3331"},
{"Name":"Jayo","Type":"Prospect","Phone":"86-(188)162-2942"},
{"Name":"Flashset","Type":"Customer","Phone":"86-(307)893-1741"},
{"Name":"Oyoyo","Type":"Prospect","Phone":"86-(429)492-9830"},
{"Name":"Oyoloo","Type":"Prospect","Phone":"374-(312)453-4457"},
{"Name":"Dabvine","Type":"Prospect","Phone":"685-(366)821-7098"},
{"Name":"Rooxo","Type":"Prospect","Phone":"48-(698)533-5970"},
{"Name":"Twimm","Type":"Customer","Phone":"64-(689)860-7262"},
{"Name":"Jabbersphere","Type":"Customer","Phone":"62-(320)896-5836"},
{"Name":"Gigazoom","Type":"Customer","Phone":"1-(324)846-5145"},
{"Name":"Zoomlounge","Type":"Prospect","Phone":"93-(814)361-9903"},
{"Name":"Miboo","Type":"Prospect","Phone":"52-(735)929-3667"},
{"Name":"Realbuzz","Type":"Prospect","Phone":"62-(875)339-5702"},
{"Name":"Livetube","Type":"Customer","Phone":"55-(808)766-8877"},
{"Name":"Bluejam","Type":"Prospect","Phone":"7-(430)324-7877"},
{"Name":"Mudo","Type":"Customer","Phone":"63-(754)334-0883"},
{"Name":"Gabspot","Type":"Prospect","Phone":"62-(101)282-2176"},
{"Name":"Devbug","Type":"Customer","Phone":"7-(448)946-9960"},
{"Name":"Mynte","Type":"Prospect","Phone":"7-(183)293-7271"},
{"Name":"Voolia","Type":"Prospect","Phone":"7-(662)678-2728"},
{"Name":"Yodo","Type":"Customer","Phone":"420-(953)324-5110"},
{"Name":"Oba","Type":"Customer","Phone":"46-(226)606-0258"},
{"Name":"Feedfire","Type":"Prospect","Phone":"420-(849)845-7410"},
{"Name":"Npath","Type":"Prospect","Phone":"55-(336)162-8610"},
{"Name":"Youspan","Type":"Prospect","Phone":"63-(363)577-9206"},
{"Name":"Devcast","Type":"Prospect","Phone":"52-(995)459-1743"},
{"Name":"Realcube","Type":"Customer","Phone":"7-(389)114-7901"},
{"Name":"Ailane","Type":"Prospect","Phone":"381-(281)279-9584"},
{"Name":"Bubblemix","Type":"Prospect","Phone":"55-(511)986-3071"},
{"Name":"Skinte","Type":"Customer","Phone":"251-(903)254-6533"},
{"Name":"Babblestorm","Type":"Customer","Phone":"55-(797)474-8121"},
{"Name":"Tagfeed","Type":"Prospect","Phone":"51-(681)185-4130"},
{"Name":"Kwimbee","Type":"Customer","Phone":"86-(807)940-6018"},
{"Name":"Jabberstorm","Type":"Prospect","Phone":"53-(603)234-5838"},
{"Name":"Meevee","Type":"Prospect","Phone":"86-(290)312-2238"},
{"Name":"Twitterbeat","Type":"Customer","Phone":"46-(727)914-9426"},
{"Name":"Mymm","Type":"Prospect","Phone":"63-(548)399-0373"},
{"Name":"Bubblemix","Type":"Customer","Phone":"33-(504)769-4714"},
{"Name":"Demimbu","Type":"Customer","Phone":"62-(783)694-9858"},
{"Name":"Aimbu","Type":"Customer","Phone":"46-(160)401-2211"},
{"Name":"Mita","Type":"Prospect","Phone":"86-(726)649-4231"},
{"Name":"Babblestorm","Type":"Prospect","Phone":"86-(651)833-1255"},
{"Name":"Eire","Type":"Prospect","Phone":"46-(857)485-6801"},
{"Name":"Yodo","Type":"Prospect","Phone":"55-(548)132-5345"},
{"Name":"Blognation","Type":"Prospect","Phone":"593-(119)795-6870"},
{"Name":"Thoughtworks","Type":"Customer","Phone":"1-(100)316-8713"},
{"Name":"Tambee","Type":"Customer","Phone":"64-(653)229-6410"},
{"Name":"Lazz","Type":"Customer","Phone":"62-(796)198-3395"},
{"Name":"Shufflebeat","Type":"Customer","Phone":"420-(516)186-0941"},
{"Name":"Browsezoom","Type":"Prospect","Phone":"58-(161)113-6245"},
{"Name":"Flashdog","Type":"Prospect","Phone":"47-(339)682-6796"},
{"Name":"Kwideo","Type":"Customer","Phone":"63-(377)678-5124"},
{"Name":"Feedbug","Type":"Customer","Phone":"62-(233)283-9873"},
{"Name":"Feedspan","Type":"Customer","Phone":"385-(797)987-1214"},
{"Name":"Skalith","Type":"Prospect","Phone":"1-(704)194-8882"},
{"Name":"Voolia","Type":"Prospect","Phone":"57-(190)791-6684"},
{"Name":"Ntag","Type":"Prospect","Phone":"66-(674)631-3758"},
{"Name":"Zoomzone","Type":"Customer","Phone":"55-(806)976-6345"},
{"Name":"Realbridge","Type":"Customer","Phone":"62-(533)615-2372"},
{"Name":"Viva","Type":"Customer","Phone":"54-(693)261-6706"},
{"Name":"Feedbug","Type":"Customer","Phone":"46-(507)901-3977"},
{"Name":"Dabfeed","Type":"Customer","Phone":"1-(585)364-0043"},
{"Name":"Einti","Type":"Prospect","Phone":"351-(276)141-8993"},
{"Name":"Twimm","Type":"Customer","Phone":"46-(148)362-9163"},
{"Name":"Lajo","Type":"Prospect","Phone":"86-(993)996-3956"},
{"Name":"Jabbercube","Type":"Customer","Phone":"20-(665)696-8460"},
{"Name":"Ozu","Type":"Customer","Phone":"48-(754)949-7043"},
{"Name":"Wordify","Type":"Prospect","Phone":"1-(430)131-4389"},
{"Name":"Demimbu","Type":"Customer","Phone":"55-(744)851-1099"},
{"Name":"Jetpulse","Type":"Customer","Phone":"593-(932)763-0307"},
{"Name":"Quatz","Type":"Prospect","Phone":"249-(904)989-2259"},
{"Name":"Fivespan","Type":"Customer","Phone":"880-(799)991-4991"},
{"Name":"Yamia","Type":"Customer","Phone":"86-(265)295-0773"},
{"Name":"Wikizz","Type":"Prospect","Phone":"1-(202)544-8397"},
{"Name":"Agimba","Type":"Prospect","Phone":"255-(462)569-2531"},
{"Name":"Meembee","Type":"Prospect","Phone":"7-(981)837-6144"},
{"Name":"Brightdog","Type":"Customer","Phone":"63-(993)436-2950"},
{"Name":"Innojam","Type":"Customer","Phone":"86-(904)244-9372"},
{"Name":"Skinder","Type":"Prospect","Phone":"62-(319)338-9503"},
{"Name":"Skibox","Type":"Customer","Phone":"86-(936)109-8180"},
{"Name":"Gabtype","Type":"Prospect","Phone":"7-(695)390-0573"},
{"Name":"Kwinu","Type":"Customer","Phone":"86-(571)833-0385"},
{"Name":"Podcat","Type":"Customer","Phone":"86-(399)217-5486"},
{"Name":"Skaboo","Type":"Customer","Phone":"48-(767)655-1582"},
{"Name":"Youspan","Type":"Customer","Phone":"63-(364)359-9512"},
{"Name":"Aivee","Type":"Customer","Phone":"977-(170)545-8731"},
{"Name":"Feednation","Type":"Customer","Phone":"81-(212)424-9461"},
{"Name":"Twitterwire","Type":"Customer","Phone":"256-(727)429-1442"},
{"Name":"Voonte","Type":"Customer","Phone":"86-(210)899-0622"},
{"Name":"Youopia","Type":"Prospect","Phone":"55-(928)221-5062"},
{"Name":"Zava","Type":"Prospect","Phone":"7-(792)923-1057"},
{"Name":"Pixonyx","Type":"Customer","Phone":"56-(742)105-5829"},
{"Name":"Katz","Type":"Prospect","Phone":"86-(276)527-0690"}
]
}
var Arrow = require('arrow');
var populateData = Arrow.API.extend({
group: 'MockData',
path: '/api/populateData',
method: 'GET',
description: 'this is an api that populates a model with mock data',
action: function (req, resp, next) {
var Model = Arrow.getModel("account");
data.forEach(function(item) {
Model.create(item, function(err, instance) {
if (err) {
console.log('Account create error');
}
});
});
next();
}
});
module.exports = populateData;
var data = [{"Name":"Jabberbean","Type":"Prospect","Phone":"62-(392)370-9245"},
{"Name":"Feedmix","Type":"Prospect","Phone":"54-(426)656-8984"},
{"Name":"Divavu","Type":"Prospect","Phone":"48-(167)609-2937"},
{"Name":"Dabtype","Type":"Customer","Phone":"970-(691)594-8951"},
{"Name":"Tagpad","Type":"Customer","Phone":"86-(994)262-7917"},
{"Name":"Yakijo","Type":"Prospect","Phone":"57-(591)899-7448"},
{"Name":"Aivee","Type":"Customer","Phone":"62-(467)735-5496"},
{"Name":"Meeveo","Type":"Customer","Phone":"507-(417)730-7508"},
{"Name":"Thoughtstorm","Type":"Prospect","Phone":"63-(655)502-2367"},
{"Name":"Oyope","Type":"Customer","Phone":"7-(439)721-4862"},
{"Name":"Eire","Type":"Customer","Phone":"86-(327)147-7181"},
{"Name":"Yotz","Type":"Customer","Phone":"34-(547)829-3300"},
{"Name":"Flashpoint","Type":"Prospect","Phone":"1-(602)419-2676"},
{"Name":"Topiczoom","Type":"Customer","Phone":"63-(391)304-9944"},
{"Name":"Rhynyx","Type":"Customer","Phone":"250-(934)741-2541"},
{"Name":"Dynabox","Type":"Prospect","Phone":"86-(831)421-7955"},
{"Name":"Nlounge","Type":"Prospect","Phone":"51-(680)100-5767"},
{"Name":"Npath","Type":"Customer","Phone":"86-(522)390-9320"},
{"Name":"Tagcat","Type":"Prospect","Phone":"371-(648)747-0038"},
{"Name":"Shuffletag","Type":"Customer","Phone":"33-(451)481-1522"},
{"Name":"Thoughtmix","Type":"Prospect","Phone":"47-(882)565-3999"},
{"Name":"InnoZ","Type":"Prospect","Phone":"86-(199)454-7379"},
{"Name":"Gabtype","Type":"Customer","Phone":"55-(739)432-5570"},
{"Name":"Oyoloo","Type":"Customer","Phone":"57-(628)787-5112"},
{"Name":"Livetube","Type":"Customer","Phone":"86-(233)211-5644"},
{"Name":"Linkbuzz","Type":"Customer","Phone":"371-(285)889-3732"},
{"Name":"Vipe","Type":"Prospect","Phone":"46-(982)645-9879"},
{"Name":"Talane","Type":"Prospect","Phone":"250-(580)635-3282"},
{"Name":"Rhyloo","Type":"Customer","Phone":"86-(199)912-8924"},
{"Name":"Flashdog","Type":"Customer","Phone":"380-(465)157-5034"},
{"Name":"Twinder","Type":"Customer","Phone":"30-(462)606-1130"},
{"Name":"Oloo","Type":"Prospect","Phone":"351-(792)829-3631"},
{"Name":"Realbuzz","Type":"Customer","Phone":"351-(567)411-3396"},
{"Name":"Flipbug","Type":"Prospect","Phone":"48-(555)472-1260"},
{"Name":"Devbug","Type":"Customer","Phone":"86-(654)532-7813"},
{"Name":"Photofeed","Type":"Prospect","Phone":"86-(660)520-5791"},
{"Name":"Leexo","Type":"Customer","Phone":"46-(643)494-9333"},
{"Name":"Jabbertype","Type":"Customer","Phone":"46-(906)841-3111"},
{"Name":"Voonder","Type":"Prospect","Phone":"7-(132)980-0487"},
{"Name":"Yabox","Type":"Customer","Phone":"962-(215)989-9051"},
{"Name":"Gabspot","Type":"Customer","Phone":"387-(819)643-8620"},
{"Name":"Browsedrive","Type":"Prospect","Phone":"62-(711)652-2056"},
{"Name":"Edgeclub","Type":"Prospect","Phone":"1-(808)804-3145"},
{"Name":"Lazzy","Type":"Customer","Phone":"374-(866)512-0299"},
{"Name":"Livepath","Type":"Prospect","Phone":"55-(104)479-1429"},
{"Name":"Eamia","Type":"Prospect","Phone":"86-(165)342-4270"},
{"Name":"Ooba","Type":"Prospect","Phone":"84-(887)412-9152"},
{"Name":"LiveZ","Type":"Customer","Phone":"86-(676)264-9738"},
{"Name":"Ainyx","Type":"Prospect","Phone":"505-(812)797-1477"},
{"Name":"Linkbridge","Type":"Customer","Phone":"62-(607)349-7333"},
{"Name":"Skyble","Type":"Prospect","Phone":"86-(751)842-0446"},
{"Name":"Camimbo","Type":"Prospect","Phone":"63-(904)312-0759"},
{"Name":"Zava","Type":"Prospect","Phone":"86-(279)694-5958"},
{"Name":"Trudoo","Type":"Customer","Phone":"84-(496)574-3595"},
{"Name":"Voonyx","Type":"Customer","Phone":"63-(997)830-8355"},
{"Name":"Realpoint","Type":"Prospect","Phone":"7-(736)886-1205"},
{"Name":"Divavu","Type":"Prospect","Phone":"63-(284)983-4164"},
{"Name":"Gabvine","Type":"Prospect","Phone":"352-(374)970-0496"},
{"Name":"Twinte","Type":"Customer","Phone":"7-(447)562-4436"},
{"Name":"Twitterwire","Type":"Prospect","Phone":"420-(926)932-0730"},
{"Name":"Shufflebeat","Type":"Prospect","Phone":"1-(668)159-5357"},
{"Name":"Topicshots","Type":"Customer","Phone":"504-(586)761-1388"},
{"Name":"Oyoyo","Type":"Customer","Phone":"380-(386)516-1085"},
{"Name":"Twitterworks","Type":"Prospect","Phone":"46-(935)489-6197"},
{"Name":"Kwideo","Type":"Customer","Phone":"86-(199)908-1385"},
{"Name":"Twimm","Type":"Prospect","Phone":"670-(986)149-5675"},
{"Name":"Skibox","Type":"Prospect","Phone":"27-(704)940-6632"},
{"Name":"Photobug","Type":"Prospect","Phone":"55-(299)978-0671"},
{"Name":"Zooveo","Type":"Customer","Phone":"232-(802)269-5848"},
{"Name":"Fatz","Type":"Customer","Phone":"48-(641)745-2999"},
{"Name":"Feedmix","Type":"Prospect","Phone":"55-(321)862-8743"},
{"Name":"Avaveo","Type":"Customer","Phone":"7-(868)177-3444"},
{"Name":"Twiyo","Type":"Customer","Phone":"373-(529)848-7789"},
{"Name":"Reallinks","Type":"Customer","Phone":"62-(888)896-7708"},
{"Name":"Kazu","Type":"Prospect","Phone":"86-(406)830-7817"},
{"Name":"Meedoo","Type":"Customer","Phone":"66-(759)660-6419"},
{"Name":"Flipbug","Type":"Prospect","Phone":"1-(260)463-0850"},
{"Name":"Livetube","Type":"Customer","Phone":"268-(396)963-6371"},
{"Name":"Vinder","Type":"Customer","Phone":"1-(107)247-8185"},
{"Name":"Twitternation","Type":"Customer","Phone":"86-(826)465-8047"},
{"Name":"Devpulse","Type":"Customer","Phone":"234-(532)647-3816"},
{"Name":"Gigaclub","Type":"Customer","Phone":"591-(632)310-2228"},
{"Name":"Zoozzy","Type":"Prospect","Phone":"55-(109)666-9165"},
{"Name":"Meemm","Type":"Prospect","Phone":"420-(673)213-8173"},
{"Name":"Edgetag","Type":"Prospect","Phone":"380-(912)104-2294"},
{"Name":"Dynabox","Type":"Prospect","Phone":"380-(445)232-6609"},
{"Name":"Skibox","Type":"Customer","Phone":"502-(250)816-1541"},
{"Name":"Realcube","Type":"Customer","Phone":"66-(564)508-4057"},
{"Name":"Dazzlesphere","Type":"Customer","Phone":"57-(202)661-6928"},
{"Name":"Skimia","Type":"Prospect","Phone":"62-(853)898-5107"},
{"Name":"Topicshots","Type":"Prospect","Phone":"595-(334)578-8234"},
{"Name":"Tambee","Type":"Prospect","Phone":"235-(721)186-0470"},
{"Name":"Zoonder","Type":"Customer","Phone":"351-(836)634-5754"},
{"Name":"Jabberstorm","Type":"Prospect","Phone":"62-(149)359-8279"},
{"Name":"Blognation","Type":"Prospect","Phone":"1-(917)122-1632"},
{"Name":"Shuffledrive","Type":"Prospect","Phone":"7-(696)636-7764"},
{"Name":"Skyble","Type":"Customer","Phone":"55-(666)274-7840"},
{"Name":"Kare","Type":"Prospect","Phone":"385-(145)243-4272"},
{"Name":"Linkbuzz","Type":"Customer","Phone":"381-(105)200-6816"},
{"Name":"Yadel","Type":"Prospect","Phone":"86-(818)912-0705"}];
var Arrow = require('arrow');
var Mockdata = require('MOCK_DATA');
var populateData2 = Arrow.API.extend({
group: 'MockData',
path: '/api/populateData2',
method: 'GET',
description: 'this is an api that populates a model with mock data from MOCK_DATA.js file',
action: function (req, resp, next) {
var Model = Arrow.getModel("account");
Mockdata.data.forEach(function(item) {
Model.create(item, function(err, instance) {
if (err) {
console.log('Account create error');
}
});
});
next();
}
});
module.exports = populateData2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment