0.0.7 • Published 4 years ago

swat-db v0.0.7

Weekly downloads
3
License
GPL-3.0
Repository
github
Last release
4 years ago

swat-db

CouchDB interface for SWAT based applications

"Making nano easier to use in the real world." - eml

In A Nut Shell:

const { db, ensureDB, ensureView, upsert } = require('swat-db');

const nano = db('http://user:pass@localhost:5984');

ensureDB(nano, 'app-data', { partitioned: true }).then(async appDB => {
  let type;
  type = 'WIDGET';
  await ensureViews(
    appDB,
    type,
    {
      'by-name': {
        map: `({type,name}) => type === '${type}' && name && emit(name.trim().toUpperCase(),name)`,
        reduce: '_count',
      },
      'by-tag': {
        map: `({type,tags}) => type === '${type}' && tags && tags.forEach(tag => emit(tag,1))`,
        reduce: '_count',
      },
    },
    { partitioned: true }
  ).then(msg => console.log(`/widgets/_design/WIDGET: ${msg}`));

  await upsert(widgets, {
    _id: 'WIDGET:foo',
    type: 'WIDGET',
    name: 'foo',
    tags: ['fast', 'easy', 'cheap'],
  })
    .then(({ id, rev }) =>
      console.log(`${id} ${rev.match(/^1-/) ? 'created' : 'updated'}`)
    )
    .catch(console.error);
});
0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago