Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
nolanlawson / index.js
Created June 25, 2014 15:38
promisy db.get
var getID = function (result) {
return result.id;
};
var db = new PouchDB('test');
return db.post({things: [1, 2, 3]})
.then(getID)
.then(function (id) {
return db.get(id);
});
@nolanlawson
nolanlawson / query_api.md
Last active August 29, 2015 14:03
Cloudant Query API - first impressions

The new Cloudant query API is pretty awesome. It basically looks like Mongo, which makes for much more readable and user-friendly queries than what you can get with standard map/reduce.

Index the field foo:

cinnabar:~ nolan$ acurl -X POST https://pouch.cloudant.com/mydb/_index -d '{
>     "index": {
>         "fields": ["foo"]
>     },
@nolanlawson
nolanlawson / index.html
Last active August 29, 2015 14:03
SQLite Plugin not as fast as I thought
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<style>
.sidebyside {
display:inline-block;
max-width: 200px;
margin: 0 30px 20px 30px;
@nolanlawson
nolanlawson / readme.md
Created July 12, 2014 02:44
Post-mortem

Quick post-mortem on this, since I think it's interesting. :)

The idea itself was excellent. By hooking into the Level* ecosystem, we got a number of different backends for free*: in-memory (both client and server), localStorage, RiakDOWN, SqlDOWN, etc.

We never did replace the IndexedDB and WebSQL adapters, though. Part of that was probably a self-fulfilling prophesy on my part, because I went to extreme lengths to get both adapters passing on Safari, IE, Android, iOS, PhantomJS, and now even the Cordova SQLite Plugin on both iOS and back to Android 2.3. Then I performance-tuned the hell out of them.

So now I think we're invested enough in idb.js and websql.js, and the performance is tuned so tightly to those specific APIs, that switching to level.js/WebDOWN/SqlDOWN would be too big a cost to bear in terms of performance (level.js is currently 2x slower). And we'd get little gain in developer efficiency, since our implementations are pretty rock-solid by now. In fact I think PouchDB may be at the forefro

@nolanlawson
nolanlawson / index.html
Created July 17, 2014 17:36
Test PouchDB Map/Reduce error 1
<html>
<body>
<script src="//cdnjs.cloudflare.com/ajax/libs/pouchdb/2.2.3/pouchdb.min.js"></script>
<script src="index.js"></script>
</body>
</html>
300340 pouchdb-new.js
134486 pouchdb-new.min.js
40975 pouchdb-new.min.js.gz
264669 pouchdb.js
113529 pouchdb.min.js
35341 pouchdb.min.js.gz
@nolanlawson
nolanlawson / index.html
Created July 19, 2014 01:03
PouchDB issue 2493
<html>
<body>
<script src="//cdnjs.cloudflare.com/ajax/libs/pouchdb/2.2.3/pouchdb.min.js"></script>
<script src="index.js"></script>
<button onclick="edit()">Edit</button>
</body>
</html>
@nolanlawson
nolanlawson / index.js
Created July 24, 2014 20:44
PouchDB storage size comparison script
var PouchDB = require('pouchdb');
var NUM_DOCS = 1000;
var dbName = 'after';
//var dbName = 'before';
var pouch = new PouchDB(dbName + '_' + NUM_DOCS);
var text =
@nolanlawson
nolanlawson / index.html
Last active August 29, 2015 14:04
PouchDB nightly fetcher
<html>
<head>
<title>
PouchDB nightly build
</title>
<style>
html {
font-family: Helvetica, Arial, sans-serif;
margin: 0 10px;
}
@nolanlawson
nolanlawson / put_example.js
Last active August 29, 2015 14:04
pouchdb "get then put" with promises
// with promises
pouch.get('id').then(null, function (err) {
if (err.code === 404) {
// not found
return {}; // default doc
}
throw err;
}).then(function (doc) {
doc.value = 'some new value';
return pouch.put(doc);