Negligible Participation Metric

npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

pouch-cli

0.0.1 • Public • Published

pouch-cli

Inspired from pouchdb-dump-cli. This module let you perform basic operations on Cloudant/CouchDB/PouchDB databases. The main mission of this module is to give quick commands to daily operations on your database. You can access it via the CLI or directly using the library.

This is currently under development so use it at your own risks.

Table of content

Installation

To install this package, simply run this command: npm i pouch-cli. If you plan to use the CLI, I suggest that you install it globally like this: npm i -g pouch-cli.

CLI

Once installed, you can use this command to access the CLI: pouch-cli.

Changelog

Coming soon.

Commands

For every commands you use, they are some global options that you need or can set.

Option Alias Type Default Required Description
-d --db string Yes The url of the database on which you want to execute your commands.
-u - - username string No The username for access to the database (if securized)
-p - - password string No Option to set the password to use during the query.

Document's commands

select <command>

To access the select commands, simply run: pouch-cli select --help.

At this level, you still have other global options.

Option Alias Type Default Description
-k --keys Array string
-r --rev boolean true Determine if the documents must be returned with their revision.
-e --with-error boolean false Determine if the document with errors should be returned.
-o --output-file string The path there the response should be saved.

From this point, you have three possible subcommands to use.

select normal

The normal select let you query the database and select particulars documents base on their ids.

For example, if we want to get the document with the _id test_doc, we would do the following:

pouch-cli select normal -k test_doc -d "http://localhost:5984/db"

You can also fetch multiple keys:

pouch-cli select normal -k "test_doc" "test_doc2" -d "http://localhost:5984/db"

select view <design/view_name>

The view subcommand let you query the documents from one of your view. It's the same usage as for the normal command except that you must specify the viewname. Here's an example:

pouch-cli select view "design_doc/view_name" -d "http://localhost:5984/db"

select dynamic <indexkey>

The dynamic subcommand let you query more dynamic queries. This is only generating basic javascript queries for you. This is not an efficient way to query your database but this can be useful for quick operations. The index key defines on what field should the document be queried. For example, if you want to get the documents based on the name, the indexkey would be name. You can also make temporary queries by using the (-udd false) option(see note below).

Note: Since CouchDB 2.0 release, the temporary views are disabled. Since PouchDB queries with temporary views are not working, you have to create a design document for your queries. Also, be aware that views are created based on the index key. For example, if you query by the name, you will have a view named "by_name".

pouch-cli select dynamic "name" -k "John" -d "http://localhost:5984/db"

delete <command>

The delete command is very similar to the select command. It let you query the documents but instead of returning the results, it deletes it. Here are listed the different global options available for this command :

Option Alias Type Default Description
-k --keys Array string

delete normal [keys]

This command is very simple. It is simply querying all the documents by the keys. If you do not specify any keys, all of the documents will be deleted.

Command examples :

pouch-cli delete normal -d "http://localhost:5984/db"

For a specific key :

pouch-cli delete normal -d "http://localhost:5984/db" -k "specific_id"

For multiple keys :

pouch-cli delete normal -d "http://localhost:5984/db" -k "first_id" "second_id"

delete view <design/view_name> [keys]

The view subcommand let you delete the documents from one of your view. It's the same usage as for the normal command except that you must specify the viewname. Here's an example:

pouch-cli delete view "design_doc/view_name" -d "http://localhost:5984/db"

delete dynamic <indexkey> [keys]

The dynamic subcommand let you delete document dynamically. This is only generating basic javascript queries for you. This is not an efficient way to query and delete documents from your database but this can be useful for quick operations. The index key defines on what field should the document be queried. For example, if you want to get the documents based on the name, the indexkey would be name. You can also make temporary queries by using the (-udd false) option(see note below).

Note: Since CouchDB 2.0 release, the temporary views are disabled. Since PouchDB queries with temporary views are not working, you have to create a design document for your queries. Also, be aware that views are created based on the index key. For example, if you query by the name, you will have a view named "by_name".

pouch-cli delete dynamic "name" -k "John" -d "http://localhost:5984/db"

Notes

This package is not stable yet, so don't put it in a production environment. CLI parameters and functions might change. I will try to write a changelog if it happens.

Contributions?

Since this module is fresh from the woods, I'm not very strict on the way of contributing to this module. Feel free to submit bugs and feature request. As the owner, I will make my possible to solve the issues and develop feature requests on my free time.

Any new feature can be discussed so it gets well implemented in the current module. Do your Pull Request with a clear understanding message of what you have done. Tests would be appreciated!

Contact

Gitter chat

You can contact me via email at alexiscote19@hotmail.com.

install

npm i pouch-cli

Downloadsweekly downloads

4

version

0.0.1

license

GPL-3.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability