This library is still in an alpha state and is not recommended for production environments. Api specs are likely to greatly change.
This library allows you to make and manage relational data in a CouchDB instance using nano (and PouchDB in the future). The goal is to give as many of the nice features of relational databases while still keeping the benefits of CouchDB.
Features are implemented using CouchDB design documents to do type checking and some basic security to maintain consistency.
Features:
- Minimal - Most methods match their Nano equivalents so if you know Nano you know RCDB.
- TypeScript - All types are documented and built in.
- Promises - Most methods return native promises.
npm install rcdb
import nano from 'nano';
import rcdb from 'rcdb';
const con = nano({
url: 'http://localhost:5984',
requestDefaults: {
jar: true,
},
});
(async () => {
await con.auth('username', 'password');
// pass a nano document scope object and a type name
const relation = await rcdb.nano.TypeScope.use(
con.use('database'),
'languages'
);
// all operations on the relation object will tag passed objects with type information
const docs = await relation.bulk({
docs: [
{ name: 'JavaScript' },
{ name: 'C++' }
]
});
/* Will output something like...
[
{
"_id": '...',
"_rev": '...',
"name": 'JavaScript',
"rcdb:_type": 'languages'
},
{
"_id": '...',
"_rev": '...',
"name": 'C++',
"rcdb:_type": 'languages'
}
]
*/
console.log(docs);
})();
opt.type
- The name of the type.
opt.indexes
- A list of field names that should be used as an index. Order does matter. The CouchDB index
view will use these fields to generate the keys.
opt.write_roles
- A list of user roles CouchDB docs which are granted access to write documents to this type. This does not restrict read access or write access to the entire database due to restrictions of CouchDB. If you want this behavior I'd recommend looking into CouchDB's database security CouchDB docs.
Tags a document with type information.
Same as nano.insert but adds type information.
const con = nano.use('database');
const langs = await TypeScope.use(con, 'languages')
await langs.insert({ id: 'ts', name: 'TypeScript' });
Same as nano.destroy
await langs.destroy('ts', '1-2a00fed267f946dbba0fccdd66520463');
Same as nano.destroy
await langs.destroy({ _id: 'ts', _rev: '1-2a00fed267f946dbba0fccdd66520463' });
Same as nano.get
await langs.get('ts');
Same as nano.head
Same as nano.bulk but adds type information.
Same as nano.list
Same as nano.listAsStream
Same as nano.fetch
Same as nano.fetchRevs
See nano's docuementation for any additional info.
You must have docker installed.
npm test
- Type based design documents
- Per type write security
- Partition types in database
- PouchDB support
- Foreign keys