couchdb-compile
Build CouchDB documents from directory, JSON or module.
API
compile(source[, options], callback)
source
- Can be a CouchDB Directory Tree (see below), a JSON file or a CommonJS moduleoptions.index
- When set totrue
, folders are searched forindex.js
, which, if present, is treated as CommonJS module. Default isfalse
.options.multipart
- When set totrue
, attachments are handled as multipart. Default isfalse
.callback
- called when done with two arguments:error
anddoc
.
In case options.multipart
is set, callback
is called with a third argument:
attachments
. This is a multipart attachments array as required by nanos
db.multipart.insert
:
{
name: 'rabbit.png',
content_type: 'image/png',
data: <Buffer>
}
data
can be a Buffer
or a String
.
Example
var compile = require('couchdb-compile');
compile('project/couchdb', function(error, doc) {
// doc is a compile object now
});
CLI
couchdb-compile [SOURCE] [OPTIONS]
When SOURCE
is omitted, the current directory will be used.
OPTIONS
can be --index
, see above.
Example
couchdb-compile project/couchdb
The CouchDB Directory Tree
couchdb-compile
uses a filesystem mapping similar to Couchapp python
tool and
Erica:
The Couchapp Filesystem
Mapping.
It is quite self-explanatory. For example:
myapp
├── _id
├── language
└── views
└── numbers
├── map.js
└── reduce.js
becomes:
{
"_id": "_design/myapp",
"language": "javascript",
"views": {
"numbers": {
"map": "function...",
"reduce": "function..."
}
}
}
See test/fixtures
and test/expected
for usage examples.
IDs
If you do not include an _id
property, the filename will be used.
File Extensions
For property names file extensions will be stripped:
{
"validate_doc_update": "content of validate_doc_update.js",
}
Attachments
Files inside the \_attachments
directory are handled special:
They become attachment entries of the form
{
"a/file.txt": {
"data": "SGVsbG8gV29ybGQhCg==",
"content_type": "text/plain"
}
}
The content\_type
is computed using mime.
data
is the base64 encoded value of the file.
Read more about Inline Attachments.
Tests
npm test
(c) 2014 Johannes J. Schmidt, TF
Apache 2.0 License