allco
clarify your async js code without plenty of try{}catch(e){}
a lib for writing i/o codes and error handling which is like coding in golang
As node supports async/await feature, we can code with less calbacks, but the same time we get a lot of try catch
codes when error handling
so, I write this lib for wrapping the natural async i/o modules.
As there is a popular node_module called co, so i name this one all-co :)
Note
this module is still being developed
Demo
use allco:
const mongodb = mongodb; { var err db = await mongodb; if err throw err; // do your error handling here let main = db; var err rep = main; if err throw err; return err rep;} ;
use native:
const mongo = MongoClient; { // do your error handling with `try/catch` try var db = await mongo; catche return console; let main = db; // ...} ;
Installation
npm install allco
Usage
Note
If you care about memory usage of allco,you can require what you need dividually.
e.g. const mongodb = require('allco/mongodb');
fs
mongodb
import:
const mongodb = mongodb; // or const mongodb = ;
connect:
// connect to dbvar err db = await mongodb;if err return console; // get a collection instancelet main = db;
retrieve:
// find with query which equals find(query).toArray((err, data) => {...})var err rep = await main;if err return console; // findOne methodvar err rep = await main;if err return console;
insert:
// insert a docvar err rep = await main;if err return console;
update:
// update a docvar err rep = await main;if err return console;
delete:
// remove a docvar err rep = await main;if err return console;