• Stars
    star
    103
  • Rank 333,046 (Top 7 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rich document ids for CouchDB

DocURI Build Status

Rich document ids for CouchDB:

'movie/blade-runner/gallery-image/12/medium'

Advantages

  • You can access the doc type everywhere (eg. in changes feed, response, view results...)
  • They sort well in Futon and _all_docs
  • DocURIs can tell a lot about the document
  • You can rely on a schema and construct ids of dependend documents (eg. a specific version of an image)
  • Easily delete related documents (eg. by requesting a range from _all_docs)

Give DocURIs a try!

Usage

Define methods for certain DocURI fragments and provide a routes hash that pairs routes to methods.
DocURI is inspired by Backbone.Router.

Routes can contain parameter parts, :param, which match a single DocURI component between slashes; and splat parts *splat, which can match any number of DocURI components. Part of a route can be made optional by surrounding it in parentheses (/:optional).

For example, a route of 'movie/:movie_id/gallery-image' will generate a function which parses

'movie/blade-runner/gallery-image/12'
// =>
{
  movie_id: 'blade-runner',
  id: '12'
}

and vice versa.

A route of 'movie/:movie_id/:type/*path' will generate a function which parses

'movie/blade-runner/gallery-image/12'
// =>
{
  movie_id: 'blade-runner',
  type: 'gallery-image',
  path: ['12']
}
// and
'movie/blade-runner/gallery-image/12/medium'
// =>
{
  movie_id: 'blade-runner',
  type: 'gallery-image',
  path: ['12', 'medium']
}

The route 'movie/:movie_id/gallery-image/:id(/:version)' will generate a function which parses

'movie/blade-runner/gallery-image/12'
// =>
{
  movie_id: 'blade-runner',
  id: '12'
}
// as well as
'movie/blade-runner/gallery-image/12/medium'
// =>
{
  movie_id: 'blade-runner',
  id: '12',
  version: 'medium'
}

docuri.route(route)

Create a single route. The route argument must be a routing string.

// parses 'page/home' as { id: 'home' }:
var page = docuri.route('page/:id');

route(strOrObj, [obj])

The functions generated by DocURI can have a different behaviour, depending on the type and number of the supplied arguments:

  • route(str): parse DocURI string to object
  • route(obj): generate DocURI string from object
  • route(str, obj): change DocURI string parts with values provided by object returning a string

The function returns false if a string can not be parsed, enabling type checks.

Example

movie('movie/blade-runner');
// { id: 'blade-runner' }
movieAsset('movie/blade-runner');
// false
galleryImage({ movie_id: 'blade-runner', id: 12 });
// 'movie/blade-runner/gallery-image/12'
galleryImage('movie/blade-runner/gallery-image/12', { version: 'large' });
// 'movie/blade-runner/gallery-image/12/large'

Browser support

To use DocURI in your client-side application, browserify it like this:

browserify -s DocURI path/to/docuri/index.js > path/to/your/assets

Or grab it from browserify-as-a-service: docuri@latest.

Development

To run the unit tests:

npm test

License

Copyright (c) 2014 Johannes J. Schmidt, null2 GmbH
Licensed under the Apache 2.0 license.

More Repositories

1

couchdb-best-practices

Collect best practices around the CouchDB universe.
CSS
320
star
2

backbone-pouch

Backbone PouchDB Adapter
JavaScript
163
star
3

couchdb-bootstrap

Bootstrap CouchDB projects: configure, setup security, deploy ddocs and create users.
JavaScript
115
star
4

puret

Puret is a minimal pure translation library for translating database values for Rails 3.
Ruby
74
star
5

pouch-box

Asymmetric encrypted PouchDB, powered by NaCl's curve25519-xsalsa20-poly1305.
JavaScript
67
star
6

grunt-couch

Build and publish Couchapps and CouchDB design documents with grunt. Simple.
JavaScript
46
star
7

couchdb-push

Deploy CouchDB documents from directory, JSON or CommonJS module.
JavaScript
40
star
8

couchdb-compile

Build CouchDB documents from directory, JSON or CommonJS module
JavaScript
38
star
9

pouch-resolve-conflicts

Assist in CouchDB conflict resolution
JavaScript
34
star
10

quilt

Access CouchDB from filesystem
Ruby
21
star
11

session25519

Derive Curve25519 encryption keys and ed25519 signing keys from username and password via BLAKE2s hash and scrypt.
JavaScript
20
star
12

roy-replicator

Node implementation of CouchDB replicator. For educational purposes.
JavaScript
20
star
13

mouch

Couchapp Purism
Ruby
19
star
14

couchmagick

Couchmagick runs ImageMagicks convert on CouchDB documents. Reliable.
JavaScript
17
star
15

couch-daemon

High-level os daemon API for CouchDB.
JavaScript
14
star
16

webcryptobox-js

Tiny utility library for asymetric encryption via WebCrypto with zero dependencies.
JavaScript
14
star
17

couchdb-worker

A worker module that manages state.
JavaScript
13
star
18

git-relax

Proof of Concept for a sync solution based on Git and Apache CouchDB
Shell
12
star
19

couchdb-configure

Configure CouchDB from file, node module or directory.
JavaScript
12
star
20

http-image-size

Detect image dimensions over http.
JavaScript
10
star
21

hello-gjs-npm

Example application demonstrating the use of Babel and Rollup to create an NPM installable and -runnable Gjs executable from ES2015 project source
JavaScript
10
star
22

couchdb-secure

Write couchdb security object from file or directory.
JavaScript
9
star
23

worker-fetch-tweets

Fetch tweets and store them in a CouchDB.
JavaScript
8
star
24

couch-box

Asymmetric encrypted CouchDB documents, powered by NaCl's curve25519-xsalsa20-poly1305.
JavaScript
7
star
25

massage-couch

Massage CouchDB documents with an os daemon worker.
JavaScript
7
star
26

microcouch-rs

A minimal Pouch-like implementation of a CouchDB compatible embeddable couch. Work in progress.
Rust
5
star
27

multipart-related

Parse `multipart/related` responses in the browser
JavaScript
5
star
28

connect-nano

req.nano, which passes session cookies to CouchDB and back again.
JavaScript
5
star
29

microcouch-js

A minimal Pouch-like implementation of a CouchDB compatible in-browser couch, for educational purpose.
JavaScript
4
star
30

couchdb-ensure

Create database unless it exists.
JavaScript
4
star
31

couch64

Handle base64 encoding and decoding inside CouchDB, eg. in list functions.
JavaScript
4
star
32

webcryptobox-rs

Utility library and CLI for WebCrypto compatible encryption
Rust
4
star
33

webcryptobox

WebCrypto compatible encryption libraries and CLIs
4
star
34

worker-generate-previews

CouchDB worker to generate previews from pdf
JavaScript
4
star
35

worker-generate-thumbnails

CouchDB worker which generates image thumbnails.
JavaScript
3
star
36

couch-daemon-bridge

Use CouchDBs os_daemons with node.
JavaScript
3
star
37

pouchdb-live-query

Provide a view which keeps itself up to date by listening to the changes feed.
JavaScript
3
star
38

global-couch-stream

Readable changes feed stream from all databases
JavaScript
3
star
39

sync-tank

Describing strategies for migrations in a distributed CouchDB world.
CSS
3
star
40

minip

Mini P is a simple database that can replicate with CouchDB.
JavaScript
3
star
41

worker-generate-stills

CouchDB worker which generates stills from videos.
JavaScript
3
star
42

i18n-tools

Tools for merging, collecting and converting i18n translations.
Ruby
3
star
43

couch-nacl-permit

Handle database permits, which encrypts a database key with a session key. For use with couch-box.
JavaScript
2
star
44

couchmagick-stream

Pipe CouchDB documents through ImageMagicks convert.
JavaScript
2
star
45

couchdb-cors-config

JavaScript
2
star
46

coup.js

Tiny script plays client side with CouchDB rewrites, lists and shows.
JavaScript
2
star
47

worker-convert

CouchDB worker which converts images
JavaScript
2
star
48

couchdb-create-index

Create CouchDB index from file or directory.
JavaScript
2
star
49

couchdb-bulk

Pipe line-seperated JSON into CouchDB
JavaScript
2
star
50

worker-fetch-json

A hoodie worker that fetches a remote JSON and inserts it into a document.
JavaScript
2
star
51

couchnacl

Use TweetNaCl.js from inside CouchDB
JavaScript
2
star
52

googlefontcssmerge

Download google font css with different user agents and combine src attributes.
JavaScript
2
star
53

couchdb-global-changes-stream

Multiplexed persisted global couchdb changes stream across all databases.
JavaScript
2
star
54

dimensionist

CouchDB daemon to extract dimensions from image attachments.
JavaScript
2
star
55

rouchdb

Minimal CouchDB compatible database written in Rust.
Rust
2
star
56

googlefontcss64

Download Google fonts and print base64 embedded style definitions.
JavaScript
2
star
57

couchdb-global-changes-rs

A global changes feed CLI in Rust [experimental]
Rust
1
star
58

urs

Ultra Responsive Slider
JavaScript
1
star
59

autoprogettazione-dinamica

JavaScript
1
star
60

tita

Things I Threw Away
HTML
1
star
61

gtk-rs-with-icons-resource

Demo project about how to work with icons and gresources on Rust GTK.
Rust
1
star
62

couchdb-flatpak-example

Example Flatpak application with CouchDB included
Shell
1
star
63

nosta

Skeleton for a small single page application based on dynamic imports
JavaScript
1
star
64

filander

Helps dealing with files and directories
Ruby
1
star
65

grunt-init-couch

Create a Couch project with grunt-init, including Nodeunit unit tests.
JavaScript
1
star
66

lena

Slick minimalistic Content Management System for artists and others.
JavaScript
1
star
67

worker-attachments

General attachments CouchDB worker.
JavaScript
1
star
68

trovebox-uploader

Upload images to trovebox like a pro
Ruby
1
star
69

tfcss

Use Cascading Style Sheets in Ruby.
Ruby
1
star
70

enzo-mari

Enzo Mari's Tavolo Rettangolare in your own dimensions
JavaScript
1
star
71

shnell

Server Setup and Configuration tools
Ruby
1
star