12 |
13 |
BrowserCouch Documentation
14 |
BrowserCouch is an attempt at an
15 | in-browser MapReduce
16 | implementation. It's written entirely in JavaScript and intended
17 | to work on all browsers, gracefully upgrading when support for
18 | better efficiency or feature set is detected.
19 |
Not coincidentally, this library is intended to mimic the
20 | functionality
21 | of CouchDB on
22 | the client-side, and may even support integration with CouchDB in
23 | the future.
24 |
25 |
Why?
26 |
27 |
This prototype is intended as a response to Vladimir
28 | Vukićević's blog post
29 | entitled HTML5
30 | Web Storage and SQL. A CouchDB-like API seems like a nice
31 | solution to persistent storage on the Web because so many of its
32 | semantics are delegated out to the JavaScript language, which
33 | makes it potentially easy to standardize. Furthermore, the
34 | MapReduce paradigm also naturally takes advantage of multiple
35 | processor cores—something that is increasingly common in
36 | today's computing devices.
37 |
38 |
Things to do
39 |
40 |
To learn how to use BrowserCouch, check out the
41 | work-in-progress tutorial.
43 |
44 |
Aside from that, you can run the test suite and the semi-large data set test, though they're not
47 | particularly exciting. In the future, we'd like to make CouchDB's
48 | Futon
49 | client work entirely using BrowserCouch as its backend instead of
50 | a CouchDB server, but that's a ways away.
51 |
52 |
If you'd like to see more code samples of what the BrowserCouch
53 | API currently looks like, check out the annotated source code for the test suite.
55 | You can also read the primary source code documentation
57 | for more on BrowserCouch's implementation.
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/html/js/test/attachment_names.js:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
2 | // use this file except in compliance with the License. You may obtain a copy of
3 | // the License at
4 | //
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to in writing, software
8 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 | // License for the specific language governing permissions and limitations under
11 | // the License.
12 |
13 | couchTests.attachment_names = function(debug) {
14 | var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"});
15 | db.deleteDb();
16 | db.createDb();
17 | if (debug) debugger;
18 |
19 | var binAttDoc = {
20 | _id: "bin_doc",
21 | _attachments:{
22 | "foo\x80txt": {
23 | content_type:"text/plain",
24 | data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
25 | }
26 | }
27 | }
28 |
29 | // inline attachments
30 | try {
31 | db.save(binAttDoc);
32 | TEquals(1, 2, "Attachment name with non UTF-8 encoding saved. Should never show!");
33 | } catch (e) {
34 | TEquals("bad_request", e.error, "attachment_name: inline attachments");
35 | TEquals("Attachment name is not UTF-8 encoded", e.reason, "attachment_name: inline attachments");
36 | }
37 |
38 |
39 | // standalone docs
40 | var bin_data = "JHAPDO*AU£PN ){(3u[d 93DQ9¡€])} ææøo'∂ƒæ≤çæππ•¥∫¶®#†π¶®¥π€ª®˙π8np";
41 |
42 | var xhr = (CouchDB.request("PUT", "/test_suite_db/bin_doc3/attachment\x80txt", {
43 | headers:{"Content-Type":"text/plain;charset=utf-8"},
44 | body:bin_data
45 | }));
46 |
47 | var resp = JSON.parse(xhr.responseText);
48 | TEquals(400, xhr.status, "attachment_name: standalone API");
49 | TEquals("bad_request", resp.error, "attachment_name: standalone API");
50 | TEquals("Attachment name is not UTF-8 encoded", resp.reason, "attachment_name: standalone API");
51 |
52 |
53 | // bulk docs
54 | var docs = { docs: [binAttDoc] };
55 |
56 | var xhr = CouchDB.request("POST", "/test_suite_db/_bulk_docs", {
57 | body: JSON.stringify(docs)
58 | });
59 |
60 | var resp = JSON.parse(xhr.responseText);
61 | TEquals(400, xhr.status, "attachment_name: bulk docs");
62 | TEquals("bad_request", resp.error, "attachment_name: bulk docs");
63 | TEquals("Attachment name is not UTF-8 encoded", resp.reason, "attachment_name: bulk docs");
64 |
65 |
66 | // leading underscores
67 | var binAttDoc = {
68 | _id: "bin_doc2",
69 | _attachments:{
70 | "_foo.txt": {
71 | content_type:"text/plain",
72 | data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
73 | }
74 | }
75 | }
76 |
77 | try {
78 | db.save(binAttDoc);
79 | TEquals(1, 2, "Attachment name with leading underscore saved. Should never show!");
80 | } catch (e) {
81 | TEquals("bad_request", e.error, "attachment_name: leading underscore");
82 | TEquals("Attachment name can't start with '_'", e.reason, "attachment_name: leading underscore");
83 | }
84 |
85 | // todo: form uploads, waiting for cmlenz' test case for form uploads
86 |
87 | };
88 |
--------------------------------------------------------------------------------
/html/js/test/all_docs.js:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
2 | // use this file except in compliance with the License. You may obtain a copy of
3 | // the License at
4 | //
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to in writing, software
8 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 | // License for the specific language governing permissions and limitations under
11 | // the License.
12 |
13 | couchTests.all_docs = function(debug) {
14 | var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"});
15 | db.deleteDb();
16 | db.createDb();
17 | if (debug) debugger;
18 |
19 | // Create some more documents.
20 | // Notice the use of the ok member on the return result.
21 | T(db.save({_id:"0",a:1,b:1}).ok);
22 | T(db.save({_id:"3",a:4,b:16}).ok);
23 | T(db.save({_id:"1",a:2,b:4}).ok);
24 | T(db.save({_id:"2",a:3,b:9}).ok);
25 |
26 | // Check the all docs
27 | var results = db.allDocs();
28 | var rows = results.rows;
29 |
30 | T(results.total_rows == results.rows.length);
31 |
32 | for(var i=0; i < rows.length; i++) {
33 | T(rows[i].id >= "0" && rows[i].id <= "4");
34 | }
35 |
36 | // Check _all_docs with descending=true
37 | var desc = db.allDocs({descending:true});
38 | T(desc.total_rows == desc.rows.length);
39 |
40 | // Check _all_docs offset
41 | var all = db.allDocs({startkey:"2"});
42 | T(all.offset == 2);
43 |
44 | // check that the docs show up in the seq view in the order they were created
45 | var changes = db.changes();
46 | var ids = ["0","3","1","2"];
47 | for (var i=0; i < changes.results.length; i++) {
48 | var row = changes.results[i];
49 | T(row.id == ids[i], "seq order");
50 | };
51 |
52 | // it should work in reverse as well
53 | changes = db.changes({descending:true});
54 | ids = ["2","1","3","0"];
55 | for (var i=0; i < changes.results.length; i++) {
56 | var row = changes.results[i];
57 | T(row.id == ids[i], "descending=true");
58 | };
59 |
60 | // check that deletions also show up right
61 | var doc1 = db.open("1");
62 | var deleted = db.deleteDoc(doc1);
63 | T(deleted.ok);
64 | changes = db.changes();
65 | // the deletion should make doc id 1 have the last seq num
66 | T(changes.results.length == 4);
67 | T(changes.results[3].id == "1");
68 | T(changes.results[3].deleted);
69 |
70 | // do an update
71 | var doc2 = db.open("3");
72 | doc2.updated = "totally";
73 | db.save(doc2);
74 | changes = db.changes();
75 |
76 | // the update should make doc id 3 have the last seq num
77 | T(changes.results.length == 4);
78 | T(changes.results[3].id == "3");
79 |
80 | // ok now lets see what happens with include docs
81 | changes = db.changes({include_docs: true});
82 | T(changes.results.length == 4);
83 | T(changes.results[3].id == "3");
84 | T(changes.results[3].doc.updated == "totally");
85 |
86 | T(changes.results[2].doc);
87 | T(changes.results[2].doc._deleted);
88 |
89 | // test the all docs collates sanely
90 | db.save({_id: "Z", foo: "Z"});
91 | db.save({_id: "a", foo: "a"});
92 |
93 | var rows = db.allDocs({startkey: "Z", endkey: "Z"}).rows;
94 | T(rows.length == 1);
95 | };
96 |
--------------------------------------------------------------------------------
/html/js/ext/lang-sql.js:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2008 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 |
16 |
17 | /**
18 | * @fileoverview
19 | * Registers a language handler for SQL.
20 | *
21 | *
22 | * To use, include prettify.js and this file in your HTML page.
23 | * Then put your code in an HTML tag like
24 | *