npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

couch-update-views

v1.0.10

Published

Update design views in a couchdb instance from json documents store locally. Update the local json document with the design view in couchdb.

Downloads

19

Readme

couch-update-views

  • Do you use git and would like to maintain a copy of your couchdb view's code in your repository?
  • Do you have multiple couchdb to maintain (production, development)?

couch-update-views allows you to synchronize design views from a local directory to your couch database. It will also help you update the JSON document of a view in your local directory with the view's content in the database.

Installing couch-update-views


npm install couch-update-views

Running couch-update-views:

Generate a script

Name your script, ex: couchUpdateViews.js and add the following lines:


var couchUpdateViews = require('couch-update-views');
couchUpdateViews.couchUpdateViews();

You should see the following output:


node couchUpdateViews.js --migrate | --update <design view name>
Options:
    --migrate    Migrate design documents in couchdb. The 'design views' in couchdb are updated with the contents of the 'viewsDir' folder if they differ.
    --update  <design view name>   Update the design view document stored in 'viewsDirs' with the document stored in 'couchDB'    
    --viewsDir <path>   Directory with desgin views documents JSON files. (required)
    --couchDB  <url>    CouchDB URL. (required)

Synchronize the DB with the folder content


node couchUpdateViews.js --migrate --viewsDir /path/to/views/folder --couchDB http://localhost:5984/dbname

If the dbname does not exist, it will create the db for you and add all the views for you.

Update a view

Generate your view using couchdb utils. If you are running couchdb locally and using the default port visit:


http://localhost:5984/_utils/database.html?dbname/_temp_view

  • Write the view's code:

In the 'Map Function' box add:


function(doc){
	if(doc.type === "user"){
		emit(doc.email, doc.name);
	}
}

  • Save the view using 'Save As...' button

Design document: _design/searchUser

View Name: email

  • Update the view's content in your local folder:

node couchUpdateViews.js --viewsDir /path/to/views/folder --couchDB http://localhost:5984/dbname --update searchUser

The output of this command yields a file named 'searchUser.json' located at '--viewsDir' folder. The content of the file should look like:


{
    "_id": "_design/searchUser",
    "language": "javascript",
    "views": {
        "email": {
            "map": "function(doc) {\n\tif(doc.type === \"user\"){\n\t\temit(doc.email, doc.name);\n\t}\n}"
        }
    }
}

Using couch-update-views w/o command line

Synchronize the DB with the folder content


var couchUpdateViews = require('couch-update-views');
couchUpdateViews.migrateUp('http://localhost:5984/dbname', '/path/to/views')//DB URL, your local folder with views
.then(function(res){
	console.log(res);//result of the operation
});

Update a view


var couchUpdateViews = require('couch-update-views');
couchUpdateViews.updateDesignDocument('http://localhost:5984/dbname', '/path/to/views', 'searchUser')//DB URL, local folder, view name
.then(function(res){
	console.log(res);//result of operation
});

Use case example when starting your server application

In this example, I'm using Hapi as my server. The plugin configuration has the couchdb url.


conf = {
	"couchdb": "http://localhost:5984/somedb",
	"dirname": "/local/path/to/views"
}


module.exports = function (server, conf) {
	
	var couchUpdateViews = require('couch-update-views');
	var path = require('path');

	/*
	*	@params couchdb, url of couchdb
	*	@params dirname, path to directory containing the json documents of views
	*	@params test, boolean to specify if it should test for differences in the view. If true, a message will be print indicating that there are differences *	in the documents. If false or undefined, whenever there are differences in the document, the view will be pushed to couchdb. 
	*/
	couchUpdateViews.migrateUp(conf.couchdb, conf.dirname, true)
	.then(function(res){
		console.log(res);//result of the operation
	});

	//Other server logic, routes etc.
}