slouch
slouch copied to clipboard
Set the dbname once
It's a pain to have to specify the database name every function call. Is there a way to configure this during instantiation so that you don't have to type it every time?
Hmm... we've found the opposite: that you want the flexibility to set the DB name without having to create an instance that is bound to the DB name, like is done in nano. We've made this easier by creating a variable like
var dbName = 'mydb';
and then using it in all the calls, e.g.
slouch.doc.create(dbName, ...);
Let me ponder this a little to see if there is some middle ground that isn't as restrictive as nano's approach. Maybe a "current/default" DB name would work.
@redgeoff not sure if you are working on this, but having curried functions would certainly help there!
const create = slouch.doc.create('dbName');
create(doc);
Yes @mariosant, a curried function would work well here! Would you like to take a stab at creating a PR that adds this? Something like
const myDB = slouch.use('dbName');
which would then allow for things like:
myDB.doc.create()
myDB.db.changes()
...
A API reference is available at https://github.com/redgeoff/slouch/wiki#table-of-contents