Last active
August 30, 2016 20:27
-
-
Save usagi/02b22620731d9226ccd4d0ed2f57401e to your computer and use it in GitHub Desktop.
CouchDB のきほんチートシート curl 編 ref: http://qiita.com/usagi/items/ffe7b2cde9f2f8b1b7f4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTP/1.1 200 OK | |
Server: CouchDB/1.6.1 (Erlang OTP/18) | |
ETag: "8-0517d1736e63d34d91db334b97a2a94b" | |
Date: Tue, 30 Aug 2016 20:21:39 GMT | |
Content-Type: text/plain; charset=utf-8 | |
Content-Length: 58 | |
Cache-Control: must-revalidate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTP/1.1 404 Object Not Found | |
Server: CouchDB/1.6.1 (Erlang OTP/18) | |
Date: Tue, 30 Aug 2016 20:21:54 GMT | |
Content-Type: text/plain; charset=utf-8 | |
Content-Length: 41 | |
Cache-Control: must-revalidate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 + 101 + 102 = 303 ( = value1 ) | |
200 + 201 + 202 = 603 ( = value2 ) | |
300 + 301 + 302 = 903 ( = value3 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
303 + 603 + 903 = 1809 ( = d2/v3 の map -> reduce 後の最終的な結果としての value ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "shows": | |
{ "s1": | |
"function ( d, r ) | |
{ | |
var hs = { }; | |
var b; | |
if ( ! d ) | |
b = 'document is n/a.'; | |
else if ( r.query.csv ) | |
{ | |
hs[ 'content-type' ] = 'text/csv'; | |
b = [ d.k1, d.k2, d.k3 ].reduce( function ( a, b ) { return a + ', ' + b; } ); | |
} | |
else | |
{ | |
hs[ 'content-type' ] = 'application/json'; | |
b = JSON.stringify( d ); | |
} | |
return { 'headers': hs, 'body': b + '\\n' }; | |
}" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<li>303 | |
<li>603 | |
<li>903 | |
</ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"info":{ | |
"db_name":"test", | |
"doc_count":8, | |
"doc_del_count":0, | |
"update_seq":100, | |
"purge_seq":0, | |
"compact_running":false, | |
"disk_size":446568, | |
"data_size":8112, | |
"instance_start_time":"1472498362522313", | |
"disk_format_version":6, | |
"committed_update_seq":100 | |
}, | |
"id":"aa", | |
"uuid":"56b000058f5a060388a4da64e7024e5d", | |
"method":"GET", | |
"requested_path":[ | |
"test", | |
"_design", | |
"d4", | |
"_show", | |
"s1", | |
"aa" | |
], | |
"path":[ | |
"test", | |
"_design", | |
"d4", | |
"_show", | |
"s1", | |
"aa" | |
], | |
"raw_path":"/test/_design/d4/_show/s1/aa", | |
"query":{ | |
}, | |
"headers":{ | |
"Accept":"*/*", | |
"Host":"127.0.0.1:5984", | |
"User-Agent":"curl/7.47.0" | |
}, | |
"body":"undefined", | |
"peer":"127.0.0.1", | |
"form":{ | |
}, | |
"cookie":{ | |
}, | |
"userCtx":{ | |
"db":"test", | |
"name":null, | |
"roles":[ | |
"_admin" | |
] | |
}, | |
"secObj":{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "views": { "v1": { "map": "function( d ) { emit( null, d.k1 + d.k2 + d.k3 ) }" } } | |
, "lists": | |
{ "l1": | |
"function ( h, r ) | |
{ | |
start( { 'headers': { 'content-type': 'text/html' } } ); | |
send( '<ul>\\n' ); | |
var row; | |
while ( row = getRow() ) | |
send( ' <li>' + row.value + '\\n' ); | |
send( '</ul>\\n' ); | |
}" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<li>303 | |
<li>603 | |
<li>903 | |
</ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "language": "javascript" | |
, "views": | |
{ "v1": | |
{ "map": | |
"function ( d ) | |
{ | |
if ( d.k1 > 200 ) | |
emit( d._id, { 'k1': d.k1, 'k2 + k3': d.k2 + d.k3 } ); | |
}" | |
} | |
, "v2": | |
{ "map": | |
"function ( d ) | |
{ | |
if ( d.k2 > 200 ) | |
emit( d._id + '-' + d.k3, null ); | |
}" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id":"_design/d1", | |
"_rev":"1-b0a42e17ff9d67143d6ef16174ee894c", | |
"language":"javascript", | |
"views":{ | |
"v1":{ | |
"map":"function ( d ) { if ( d.k1 > 200 ) emit( d._id, { 'k1': d.k1, 'k2 + k3': d.k2 + d.k3 } ); }" | |
}, | |
"v2":{ | |
"map":"function ( d ) { if ( d.k2 > 200 ) emit( d._id + '-' + d.k3, null ); }" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"total_rows":1, | |
"offset":0, | |
"rows":[ | |
{ | |
"id":"ccc", | |
"key":"ccc", | |
"value":{ | |
"k1":300, | |
"k2 + k3":603 | |
} | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"total_rows":2, | |
"offset":0, | |
"rows":[ | |
{ | |
"id":"bbb", | |
"key":"bbb-202", | |
"value":null | |
}, | |
{ | |
"id":"ccc", | |
"key":"ccc-302", | |
"value":null | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "views": | |
{ "v3": | |
{ "map" : "function ( d ) { emit( d._id, d.k1 + d.k2 + d.k3 ) }" | |
, "reduce": "function ( k, v, r ) { return sum( v ) }" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id":"_design/d2", | |
"_rev":"1-0a71c65253d237bbc66aa4df3b1f2d11", | |
"views":{ | |
"v3":{ | |
"map":"function ( d ) { emit( d._id, d.k1 + d.k2 + d.k3 ) }", | |
"reduce":"function ( k, v, r ) { return sum( v ) }" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rows":[ | |
{ | |
"key":null, | |
"value":1809 | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"id":"aaa","key":"aaa","value":{"rev":"1-c8227456e13a740a3a950be456a85f21"},"doc":{"_id":"aaa","_rev":"1-c8227456e13a740a3a950be456a85f21","k1":100,"k2":101,"k3":102}}, | |
{"id":"bbb","key":"bbb","value":{"rev":"1-ea6f81f73a3bf9c1dc3391565b740870"},"doc":{"_id":"bbb","_rev":"1-ea6f81f73a3bf9c1dc3391565b740870","k1":200,"k2":201,"k3":202}}, | |
{"id":"ccc","key":"ccc","value":{"rev":"1-5bac6f87d40c8d92da4a0586361bb950"},"doc":{"_id":"ccc","_rev":"1-5bac6f87d40c8d92da4a0586361bb950","k1":300,"k2":301,"k3":302}} | |
]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment