pouchdb-model
Convenient Wrapper for PouchDB
Install
$ npm install --save pouchdb-model
Examples
- examples/simple (inlined below) - no schema / no validation
- examples/tcomb - schema and validation by tcomb
;; // if you don't use migrations, you could omit this import;PouchDB; const File = name migrations: { if docfoo return; docfoo = true; return doc; } indexes: name: 'updatedAtIndex' { ; } ; { const File = await const docA = await File; /* { name: 'user-a', _id: 'user-a', updatedAt: '2016-11-03T19:35:19.869Z', _rev: '1-1ccfb26dd920cbf8ac11c965efac73d9' } */ const docB = await File; /* { name: 'user-b', _id: 'user-b', updatedAt: '2016-11-03T19:36:16.827Z', _rev: '1-7ce9e72b2c2ed18fd1753e0c6627e6b0' } */ const docs = await File; /* [ { name: 'user-a', updatedAt: '2016-11-03T19:38:44.765Z', _id: 'user-a', _rev: '1-722dd9fc99ef1f04334544bc01e0639a', _key: 'user-a' }, { name: 'user-b', updatedAt: '2016-11-03T19:38:44.766Z', _id: 'user-b', _rev: '1-b3b0f835f60044a68faf04e80a91ced7', _key: 'user-b' } ] */ const docsByUpdateAt = await File; /* [ { name: 'user-b', updatedAt: '2016-11-03T19:45:27.729Z', _id: 'user-b', _rev: '1-ab63623e330d68e060bc2f93ddab0279', _key: '2016-11-03T19:39:27.403Z$user-b' }, { name: 'user-a', updatedAt: '2016-11-03T19:45:27.728Z', _id: 'user-a', _rev: '1-c6da589a48e47402198e145ace61155f', _key: '2016-11-03T19:39:27.403Z$user-a' } ] */} try ; catch e console;
Methods
#createId(data: Object)
Returns the _id
field in data
or new id generated by a function provided in an initializer
#findById(id: String)
#findOne(data: Object)
#findAll(options: Object?)
#findByIndex(options: Object?)
#put(data: Object)
#update(data: Object)
Overwrites the previous object if existed with a correct _rev
or insert a new doc
#bulk(data: Object[])
Returns an array of the same length containing corresponding doc (has _id
and _rev
)
or error (has error
, name
, status
and, in case of validation error - err
)
#sync(db: PouchDB | String, options: Object?, notify: Function)
Changelog
v0.4.0
createdAt
property
Related
License
MIT © ewnd9