-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import from original, clean up HTML, extract CSS, add json2.js and jq…
…uery-1.3.2.min.js, rename to jscouch
- Loading branch information
Jan Lehnardt
committed
Apr 13, 2009
0 parents
commit fa39d87
Showing
5 changed files
with
1,542 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* "THE BEER-WARE LICENSE" (Revision 42): | ||
* Mu Dynamics Research Labs wrote this file. As long as you retain this | ||
* notice you can do whatever you want with this stuff. If we meet some day, | ||
* and you think this stuff is worth it, you can buy us a beer in return. | ||
* | ||
* http://www.mudynamics.com | ||
* http://labs.mudynamics.com | ||
* http://www.pcapr.net | ||
*/ | ||
body { | ||
background-color: rgb(244, 244, 244); | ||
color: rgb(51, 51, 51); | ||
line-height: 135%; | ||
font-size: 13px; | ||
font-family: Arial, Helvetica, sans-serif; | ||
} | ||
|
||
select, textarea, input { | ||
font-size: 13px; | ||
font-family: Arial, Helvetica, sans-serif; | ||
} | ||
|
||
.icouch fieldset#tabs legend a { | ||
background-color: transparent; | ||
margin: 2px; | ||
padding: 2px; | ||
border: none; | ||
text-decoration: none; | ||
outline: none; | ||
} | ||
|
||
.icouch fieldset#tabs legend a.active { | ||
background-color: #dddddd; | ||
border: 1px solid #9aafe5; | ||
} | ||
|
||
.icouch select { | ||
vertical-align: middle; | ||
} | ||
|
||
.icouch a { | ||
cursor: pointer; | ||
color: rgb(39, 39, 192); | ||
} | ||
|
||
.icouch a:hover { | ||
color: black; | ||
} | ||
|
||
.icouch div#doc { | ||
margin-left: 20px; | ||
} | ||
|
||
.icouch table#docs thead td { | ||
font-weight: bold; | ||
} | ||
|
||
.icouch table#docs td { | ||
border-bottom: 1px inset #9aafe5; | ||
} | ||
|
||
.icouch table#docs tbody tr:hover { | ||
background-color: #dddddd; | ||
} | ||
|
||
.icouch div#map textarea { | ||
background-color: #fff8dc; | ||
margin-left: 20px; | ||
width: 80%; | ||
} | ||
|
||
.icouch div#map table#results thead td { | ||
font-weight: bold; | ||
} | ||
|
||
.icouch div#map table#results tbody td.reduced { | ||
vertical-align: middle; | ||
border-left: 2px dotted #9aafe5; | ||
} | ||
|
||
.icouch div#map table#results tbody tr:hover { | ||
background-color: #dddddd; | ||
} | ||
|
||
.icouch div#blurb { | ||
margin-left: 20px; | ||
padding-left: 20px; | ||
border-left: 2px dotted #9aafe5; | ||
color: #000088; | ||
} | ||
|
||
img.icon { | ||
vertical-align: middle; | ||
border: none; | ||
width: 16px; | ||
} | ||
|
||
.jstring { color: #008800; } | ||
.jnumber { color: #880000; } | ||
.jkeyword { color: #000088; } | ||
|
||
.credits { | ||
margin: -10px 0 2ex 20px; | ||
font-size: 10pt; | ||
} | ||
|
||
.intro { | ||
margin-bottom:2ex; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<!-- | ||
/* | ||
* "THE BEER-WARE LICENSE" (Revision 42): | ||
* Mu Dynamics Research Labs wrote this file. As long as you retain this | ||
* notice you can do whatever you want with this stuff. If we meet some day, | ||
* and you think this stuff is worth it, you can buy us a beer in return. | ||
* | ||
* http://www.mudynamics.com | ||
* http://labs.mudynamics.com | ||
* http://www.pcapr.net | ||
*/ | ||
--> | ||
<title>Interactive CouchDB | Mu Dynamics</title> | ||
<meta name="robots" content="index, follow"> | ||
<meta name="description" content="A JavaScript-based CouchDB emulator that implements key CouchDB concepts like collation, map/reduce and incremental reduce. This also serves as a 2 minute CouchDB tutorial."> | ||
<meta http-equiv="content-type" content="text/xhtml; charset=utf-8" /> | ||
|
||
<link rel="stylesheet" href="jscouch.css" type="text/css" media="screen" charset="utf-8"> | ||
<script type="text/javascript" src="jquery-1.3.2.min.js"></script> | ||
<script type="text/javascript" src="json2.js"></script> | ||
<script type="text/javascript" src="jscouch.js"></script> | ||
</head> | ||
<body> | ||
|
||
<h2>Interactive CouchDB</h2> | ||
|
||
<div class="credits"> | ||
created by | ||
<img class="icon" src="http://www.pcapr.net/static/image/favicon.png"> | ||
<a href="http://www.mudynamics.com">Mu Dynamics</a> | ||
for this <a href="http://labs.mudynamics.com/2009/04/03/interactive-couchdb/">blog</a>. | ||
</div> | ||
|
||
<div class="intro"> | ||
This is a CouchDB emulator/visualizer written in 100% JavaScript, which | ||
implements key concepts like collation, map/reduce and incremental reduce. It | ||
also acts as a 2-minute CouchDB tutorial. No documents were harmed in this | ||
process. | ||
</div> | ||
|
||
<div class="icouch"> | ||
<fieldset id="tabs"> | ||
<legend> | ||
<a id="documents" href="javascript:void(0)" class="active">documents</a> | ||
<a id="map" href="javascript:void(0)" class="">map/reduce</a> | ||
</legend> | ||
|
||
<div id="pane"> | ||
<div id="documents" style=""> | ||
<div> | ||
<p> | ||
<a href="http://couchdb.apache.org/">CouchDB</a> stores | ||
schema-less JSON documents in a flat namespace. | ||
Each document has an <em>id</em> that's either auto generated | ||
or provided by the user. The JSON documents can be as simple | ||
or as complex as it can be. You can think of each document as | ||
an instance of a particular <strong>class</strong>. CouchDB | ||
doesn't know or track relationships between documents. It's up | ||
to you to keep track of that.</p> <p>The sample DB below | ||
contains information about a bunch of pictures uploaded and | ||
tagged by different users with some meta data about each | ||
picture. | ||
</p> | ||
</div> | ||
|
||
<table id="docs" width="100%"> | ||
<colgroup> | ||
<col span="1"> | ||
<col width="100%"> | ||
</colgroup> | ||
<thead> | ||
<tr> | ||
<td>id</td> | ||
<td>doc</td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
</tbody> | ||
</table> | ||
» <a id="add" href="javascript:void(0)">add</a> | ||
<div id="doc" style="display: none"> | ||
<textarea id="doc" rows="4" cols="60"></textarea> | ||
<div> | ||
<input type="button" value="apply"> | ||
<span class="warn" style="color: red"></span> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div id="map" style="display: none; "> | ||
<div> | ||
<p> | ||
Now that we have the documents in place, we can use the | ||
<strong>map</strong> function to generate complex key | ||
value pairs (sorted by key) and then | ||
<strong>reduce</strong> the values corresponding to each | ||
unique key into either a simple or complex value. | ||
</p> | ||
<p> | ||
This is a very key concept so it's worth reiterating. The | ||
key/value pairs generated by the <strong>map</strong> | ||
function are stored in a BTree and are updated incrementally | ||
as documents are added or updated. The query against a | ||
view is simply slicing this sorted key space, potentially | ||
<strong>reducing</strong> the slice and returning the | ||
values. CouchDB will cache the reduced values in the BTree | ||
as well and will try and reuse these cached values during | ||
the key-space slicing, a.k.a. query. | ||
</p> | ||
<p> | ||
Try and learn: | ||
<select id="examples"> | ||
<option>choose one</option> | ||
</select> | ||
</p> | ||
<div id="blurb"></div> | ||
</div> | ||
|
||
<table style="margin-top: 10px" width="100%"> | ||
<tbody> | ||
<tr> | ||
<td width="50%"> | ||
<div> | ||
<div>function(<strong>doc</strong>) {</div> | ||
<div> | ||
<textarea id="map" rows="6">emit(null, null);</textarea> | ||
</div> | ||
<div>}</div> | ||
</div> | ||
</td> | ||
<td width="50%"> | ||
<div> | ||
<div>function(keys, values, <strong>rereduce</strong>) {</div> | ||
<div> | ||
<textarea id="reduce" rows="6"></textarea> | ||
</div> | ||
<div>}</div> | ||
</div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<div> | ||
» | ||
<a id="execute" href="javascript:void(0)">execute</a> | ||
<span class="warn" style="color: red"></span> | ||
</div> | ||
|
||
|
||
<table id="bottom" width="100%" style="display:none"> | ||
<tbody> | ||
<tr> | ||
<td valign="top" width="50%"> | ||
<table id="results"></table> | ||
</td> | ||
<td valign="top" width="50%"> | ||
<div> | ||
query: | ||
<select id="view"> | ||
<option>all</option> | ||
<option>key</option> | ||
<option>range</option> | ||
</select> | ||
<span id="views"> | ||
<span id="all"> | ||
</span> | ||
<span id="key" style="display:none"> | ||
<input id="key" type="text" size="12"> | ||
</span> | ||
<span id="range" style="display:none"> | ||
between <input id="startkey" type="text" size="12"> | ||
and <input id="endkey" type="text" size="12"> | ||
</span> | ||
</span></div> | ||
<div id="response"></div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.