1. コマンド・リファレンス

1-1. 概要

YALTools Commands Overview

[ chapter top | page top ]

1-2. 共通オプション

大半のコマンドは次のようなオプションを受け付けます。 各コマンドで実行可能なオプションのリストは"--help"を参照してください。

1-2-1. -d (デバッグモードの有効化)

このオプションは詳細なメッセージを標準エラーに出力します。

1-2-2. -f 入力ファイル (default: '-')

このオプションでは標準入力とファイル入力を切り替えることができます。

'-' は標準入力として扱われ、他の文字列は全てファイル名として認識されます。

1-2-3. -o 出力ファイル (default: '-')

このオプションでは標準出力とファイル出力を切り替えることができます。

引数はファイル名として認識され、'-'を指定した場合は標準出力として扱われます。

1-2-4. -x ラベル名

YAML形式の設定ファイル中のラベル名を指定します。デフォルト値は "default.user" です。

CouchDBにアクセスするコマンドのみで有効です。

1-2-5. -y 設定ファイル

YAML形式の設定ファイルへのパスを指定します。

CouchDBにアクセスするコマンドのみで有効です。

[ chapter top | page top ]

2. DB管理者向けのコマンド

2-1. sbin/mkdb

"mkdb" creates a new database.

$ ./mkdb dbname
{"ok":true}

[ chapter top | page top ]

2-2. sbin/lsdb

"lsdbs" shows the list of the existing databases.

$ ./lsdbs
{"database":[
  "_users",
  "dbname",
  "test"
]}

[ chapter top | page top ]

2-3. sbin/rmdb

"rmdb" deletes the existing database without notice.

$ ./rmdb dbname

[ chapter top | page top ]

3. 文書処理向けのコマンド

3-1. bin/lsdocs

"lsdocs" sends a GET request and shows all documents through the /dbname/_all_docs interface.

To optimize performance, "lsdocs" uses skip and limit parameters in the internal processing.

$ ./lsdocs test
{"_id":"65f26940ca75a1a4c3e7c6c64700077f","_rev":"1-0e7d0229c150cae8d724af06e0344b51","name":"yasu","age":"20"}
{"_id":"65f26940ca75a1a4c3e7c6c647000791","_rev":"1-ab6f8885ac4a3fa94fb23cb84f6939dc","name":"abe","age":"18"}

[ chapter top | page top ]

3-2. bin/postdocs

"postdocs" is a tool to send a POST request throught the /_bulk_docs interface.

$ echo -e '{"name":"foo"}\n{"name":"bar"}' | ./postdocs test
{"failed_list":[]}
$ ./lsdocs test
{"_id":"65f26940ca75a1a4c3e7c6c64700077f","_rev":"1-0e7d0229c150cae8d724af06e0344b51","name":"yasu","age":"20"}
{"_id":"65f26940ca75a1a4c3e7c6c647000791","_rev":"1-ab6f8885ac4a3fa94fb23cb84f6939dc","name":"abe","age":"18"}
{"_id":"65f26940ca75a1a4c3e7c6c647001524","_rev":"1-bc98e8ae0f9c89fbc8c237dfc9bfe478","name":"foo"}
{"_id":"65f26940ca75a1a4c3e7c6c647001622","_rev":"1-62bc3c4d01e43ee9d0cead8cd7c76041","name":"bar"}

The following commands delete some documents from the "test" database.

$ ./lsdocs test | ./chjson '["_deleted",true]' | ./postdocs test
{"failed_list":[]}
$ ./lsdocs test
$

[ chapter top | page top ]

4. ビュー処理向けのコマンド

4-1. bin/putdesign

"putdesign" takes the two arguments, dbname and docname, and puts reading data into the given path, /dbname/_design/docname.

$ echo '{"views":{"all":{"map":"function(doc) { emit(doc._id,null); }"}}}' | ./putdesign test all

[ chapter top | page top ]

4-2. bin/lsviews

"lsviews" shows all documents of the specified view.

After executing the example of "putdesign" to the empty "test" database, following commands show the result of "lsviews."

$ echo -e '{"name":"foo"}\n{"name":"bar"}' | ./postdocs test
{"failed_list":[]}
$ ./lsviews test all all
{"_id":"65f26940ca75a1a4c3e7c6c647002514","_rev":"1-bc98e8ae0f9c89fbc8c237dfc9bfe478","name":"foo"}
{"_id":"65f26940ca75a1a4c3e7c6c647003231","_rev":"1-62bc3c4d01e43ee9d0cead8cd7c76041","name":"bar"}

[ chapter top | page top ]

5. JSONストリーム向けのコマンド

For json stream, YALTools provides some commands like "grep" in unix environment.

5-1. bin/grepjson

"grepjson" searches the inputs for lines containing specified condition.

The condition is JSON arrays and specified by an array, such as ["key1","key2",...,"value"].

$ echo -e '{"a":"1"}\n{"b":{"c":30}}' | ./grepjson '["b","c"]'
{"b":{"c":30}}
$ echo -e '{"a":"1"}\n{"b":{"c":30}}' | ./grepjson '["b","c",30]'
{"b":{"c":30}}

[ chapter top | page top ]

5-2. bin/chjson

"chjson" adds or overwrites the given key-value pair into each line.

The following command line will add the delete flag for /_bulk_docs api.

$ ./lsdocs test | ./chjson '["_deleted",true]'
{"_id":"65f26940ca75a1a4c3e7c6c647002514","_rev":"1-bc98e8ae0f9c89fbc8c237dfc9bfe478","name":"foo","_deleted":true}
{"_id":"65f26940ca75a1a4c3e7c6c647003231","_rev":"1-62bc3c4d01e43ee9d0cead8cd7c76041","name":"bar","_deleted":true}
{"_id":"_design/all","_rev":"17-a29e5cc677328801f05a869f76a2f0f4","views":{"all":{"map":"function(doc) { emit(doc._id,null); }"}},"_deleted":true}

[ chapter top | page top ]

5-3. bin/reducejson

"reducejson" pulls out some key-value pairs to construct new json line.

$ echo '{"_id":"xxx","_rev":"yyy","name":"zzz"}' | ./reducejson '["_id","name"]'
{"_id":"xxx","name":"zzz"}

5-3-1. -e: exclude option

"reducejson -e" removes key-value pairs from the given list.

$ echo '{"_id":"xxx","_rev":"yyy","name":"zzz"}' | ./reducejson -e '["_rev"]'
{"_id":"xxx","name":"zzz"}

[ chapter top | page top ]

5-4. bin/jsonfmt

"jsonfmt" reads each line from stdin or a file and pass it to YALTools::JsonFormatter#parse module method.

	

[ chapter top | page top ]

5-5. bin/csv2json

"csv2json" is a tool to parse a csv file and produce json format string.

However, this command is not well-known csv2json script. There are some unique rules for the transformation.

## rule 1.
    | key1 | key2 | 
    |=============|  => key1:val1,key2:val2
    | val1 | val2 |
    +-------------|
    
    $ echo -e "key1,key2\nval1,val2" | bin/csv2json
    > {"key1":"val1","key2":"val2"}
## rule 2.
    | key1 | key2 | 
    |=============|   => key1:{key2:val1}
    |      | val1 |
    +-------------+

    $ echo -e "key1,key2\n,val2" | bin/csv2json
    > {"key1":{"key2":"val2"}}
## rule 3.
    | key1 | 
    |======|
    | val1 |   => key1:[val1,val2]
    |------|
    | val2 |
    +------+
    
    $ echo -e "key1\nval1\nval2" | bin/csv2json
    > {"key1":["val1","val2"]}

The "-n" options is available for the intuitive behavior.

$ echo -e "key1,key2\nval1,val2\nval3,val4" | bin/csv2json 
{"key1":["val1","val3"],"key2":["val2","val4"]}
$ echo -e "key1,key2\nval1,val2\nval3,val4" | bin/csv2json -n
{"key1":"val1","key2":"val2"}
{"key1":"val3","key2":"val4"}

[ chapter top | page top ]

6. その他、雑多なコマンド

6-1. bin/lsdoc

"lsdoc" is a tool to send a GET request to CouchDB.

$ bin/lsdoc /test/_security
	{"admin":{"names":[""],"roles":["fwadmin","fwwriter"]},"reader":{"names":[""],"roles":["fwreader"]}}

[ chapter top | page top ]

6-2. bin/putdoc

"putdoc" is a tool to send a PUT request to CouchDB.

[ chapter top | page top ]

6-3. bin/postdoc

"postdoc" is a tool to send a PUT request to CouchDB.

The functionality is same as the "putdoc" command.

The POST request is required to create "_id" less document and required for replication and compaction in CouchDB.
$ bin/postdoc /test/_compact < /dev/null
	{"ok":true}

[ chapter top | page top ]

6-4. sbin/senduri

"senduri" shows the result of the request using the YAML configuration file.

$ ./senduri /test/_all_docs

[ chapter top | page top ]

6-5. sbin/sendurl

"sendurl" shows the result of the request by the URL.

It does not use the YAML configuration file.

./sendurl http://localhost:5984/_all_dbs

[ chapter top | page top ]

Permalink: /0.1/commands.html

Created: 2011-03-01T14:59:23+09:00
Last modified: 2011-03-13T21:56:01+09:00

lscouchdb.sourceforge.net / 2011 © Yasuhiro ABE <yasu@yasundial.org> JabberID: yadiary@jabber.org

Valid XHTML + RDFa 正当なCSSです!
RDFa it (RDF/XML)!

Creative Commons License lscouchdb.sourceforge.net by Yasuhiro ABE is licensed under a Creative Commons Attribution 2.1 Japan License. Permissions beyond the scope of this license may be available at http://lscouchdb.sourceforge.net/license.html.