Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.state
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
language: node_js

env:
global:
- FORCE_COLOR=1

node_js:
- '10'

cache:
directories:
- ~/.npm

before_install:
- npm install -g npm@6

script:
# - npm run lint
- npm test

stages:
- test

branches:
only:
- master
38 changes: 20 additions & 18 deletions db.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const _ = require('highland');
const MongoClient = require('mongodb').MongoClient
var db
var mongo
var GENES
var Manager
const init = function(genes) {
GENES = genes
Manager = {}
let promises = GENES.map(function(gene, index) {
Manager = {}
const promises = GENES.map(function(gene) {
return new Promise(function(resolve) {
MongoClient.connect(process.env.PLANA_DB_URL, {useNewUrlParser: true}, function(err, client) {
if (err) console.log(err)
Expand All @@ -21,13 +19,15 @@ const init = function(genes) {
})
return Promise.all(promises)
}
const exit = function() {
let promises = Object.keys(Manager).map(function(address) {
const exit = async function() {
const promises = Object.keys(Manager).map(function(address) {
return new Promise(function(resolve) {
Manager[address].mongo.close()
resolve()
})
})
GENES = undefined
Manager = undefined
return Promise.all(promises)
}

Expand All @@ -47,14 +47,16 @@ const exit = function() {
*
***************************************/
const instances = async function() {
return Object.keys(Manager).map(async function(address) {
let infos = await Manager[address].db.listCollections().toArray()
let collectionNames = infos.map(function(info) { return info.name })
return {
address: address,
names: collectionNames
}
})
return Promise.all(
Object.keys(Manager).map(async function(address) {
let infos = await Manager[address].db.listCollections().toArray()
let collectionNames = infos.map(function(info) { return info.name })
return {
address: address,
names: collectionNames
}
})
)
}

/***********************************
Expand All @@ -69,7 +71,7 @@ const instances = async function() {
* onchunk: function(chunk) { },
* onfinish: function() { },
* })
*
*
* // Multi item batch insert
* db.create({
* address: PLANARIA_ADDRESS,
Expand All @@ -78,7 +80,7 @@ const instances = async function() {
* onchunk: function(chunk) { },
* onfinish: function() { },
* })
*
*
*
* 2. Read
*
Expand All @@ -93,7 +95,7 @@ const instances = async function() {
* skip: SKIP,
* }
* })
*
*
*
* 3. Update: Delete and Insert
*
Expand All @@ -109,7 +111,7 @@ const instances = async function() {
* },
* map: MAP_FUNCTION
* })
*
*
*
* 4. Delete
*
Expand Down
Loading