slouch icon indicating copy to clipboard operation
slouch copied to clipboard

Set the dbname once

Open mikeymckay opened this issue 7 years ago • 3 comments

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?

mikeymckay avatar Aug 09 '17 20:08 mikeymckay

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 avatar Aug 09 '17 20:08 redgeoff

@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);

mariosant avatar Jul 24 '18 12:07 mariosant

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

redgeoff avatar Jul 24 '18 15:07 redgeoff