Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
couchinator
Advanced tools
Fixtures for Cloudant: Create and destroy cloudant databases with ease
Fixtures for CouchDB and IBM Cloudant.
Setup and teardown CouchDB and IBM Cloudant databases with ease. couchinator is a great tool for unit/integration testing and more. couchinator is both a library and a command line utility.
Represent your database(s) as a set of folders and files and couchinator takes care of the rest.
See the Data Layout section for information on how to represent your database with couchinator.
npm install couchinator
Global installation is convenient when using the CLI
npm install couchinator -g
If you're a Java user, try this
couchinator create --url http://127.0.0.1:5984 --path ./fixtures
couchinator create --url <COUCHDB-OR-CLOUDANT-URL> --path <RESOURCE_PATH>
couchinator destroy --url <COUCHDB-OR-CLOUDANT-URL> --path <RESOURCE_PATH><br>
couchinator recreate --url <COUCHDB-OR-CLOUDANT-URL> --path <RESOURCE_PATH>
Note: RESOURCE_PATH
may be absolute path or a path relative to the current working directy
const Couchinator = require('couchinator');
const couchinator = new Couchinator('http://127.0.0.1:5984').resources(
'./fixtures'
);
// Each of the following methods return a promise
couchinator.create();
couchinator.recreate();
couchinator.destroy();
see Advanced Usage for more library customization options
The following sections describe how to create a data layout.
To skip directly to a working example, go here
Couchinator enables you to represent CouchDB and Cloudant database(s) using a simple filesystem structure that mimics the actual database structure.
A couchinator filesystem data layout might look as such:
users
_design
students.json
teachers.json
students-docs.json
teachers-docs.json
classrooms
_design
classrooms.json
classrooms-docs.json
Let's create a data layout to describe two databases users and classrooms
Create two folders, one for users
and another for classrooms
.
users/
classrooms/
Note: Couchinator will use the folder name as the database name
Within each folder optionally create a _design
folder to store any design documents
users/
_design/
classrooms/
_design/
Create design document(s) and store them in the appropriate _design
folder
In the example below, we create two design documents in the schools
database and one in the users
database.
users/
_design/
students.json
teachers.json
classrooms/
_design/
classrooms.json
The contents of each design document .json
must be a valid CouchDB design document.
For example, students.json
:
{
"_id": "_design/students",
"views": {
"byId": {
"map": "function (doc) { if (doc.type === 'student') emit(doc._id, doc);}"
}
},
"language": "javascript"
}
Create the data to store in each database
users/
_design/
students.json
teachers.json
students-docs.json # contains student data
teachers-docs.json # contains teacher data
classrooms/
_design/
classrooms.json
users-docs.json
For example, student-docs.json
contains students
{
"docs": [
{
"_id": "sam895454857",
"name": "Sam C.",
"type": "student"
},
{
"_id": "josie895454856",
"name": "Josie D.",
"type": "student"
}
]
}
Run couchinator to create each database
Assuming the data layout is stored in the folder ./fixtures
, run the following command(s):
couchinator create --url http://127.0.0.1:5984 --path ./fixtures
To view a complete data layout example, see examples/db-resources.
To run the the example:
cd examples
<CLOUDANT-URL>
to your cloudant urlnode example
var cloudant = Cloudant({account:me, password:password}); If you would prefer, you can also initialize Cloudant with a URL:
const url = 'https://MYUSERNAME:MYPASSWORD@MYACCOUNT.cloudant.com';
new Couchinator(url);
const url = 'https://MYUSERNAME:MYPASSWORD@MYACCOUNT.cloudant.com';
new Couchinator({ account: me, password: password });
The couchinator library enables a variety of customizations, including the ability to provide a custom visitor to configure exactly what log information is output.
const Generator = require('couchinator');
const path = require('path');
// Define the directory that contains our db resources
const resourcePath = path.join(process.cwd(), 'db-resources');
const c = new Couchinator('<YOUR-DB-URL>')
.resources(resourcePath)
.visitor(e => {
if (e.level >= 30) console.log(e.msg);
})
.configure();
couchinator create
Creates all databases, design documents, and executes any bulk documents represented in the data layout. If a design document exists, the design document is updated to reflect the version currently represented in the data layout.
Using the --ddocsonly
flag skips any bulk documents. This flag is particulary useful when you simply want to add/update design documents.
couchinator destroy
destroys all databases represented in the data layout.
couchinator rcreate
Calls destroy followed by create.
See CLI Usage section for additional arguments.
Currently, the CLI only support a Cloudant URL.
> couchinator
Usage: couchinator [options] [command]
Commands:
create
recreate
destroy
Options:
-h, --help output usage information
-V, --version output the version number
-u --url <url> couchdb url
-p --path <path> resource path. Default ./fixtures
-b --verbose verbose logs
-d --ddocsonly import design docs only. Do no import other docs
FAQs
Fixtures for Cloudant: Create and destroy cloudant databases with ease
The npm package couchinator receives a total of 3 weekly downloads. As such, couchinator popularity was classified as not popular.
We found that couchinator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.