calendar-db
store and query recurring and one-time events
example
add
var level =var db =var calendar =var cal =var time = processargv2var opts =value: title: processargv3cal
$ date
Mon May 23 16:09:11 CEST 2016
$ node add.js 'every thursday' 'javascript study group'
4e9007c81c2c50ee373c9d69c94259ad
$ node add.js 'tuesday may 24th' 'open hack'
6538b3a92859e99267ad45b15ae6ab1d
range
var level =var db =var minimist =var argv =var calendar =var cal =cal
$ node range.js --gt 2016-05-01 --lt 2016-06-01
{ key: '4e9007c81c2c50ee373c9d69c94259ad',
time: Thu May 05 2016 00:00:00 GMT+0200 (CEST),
value: { title: 'javascript study group' } }
{ key: '4e9007c81c2c50ee373c9d69c94259ad',
time: Thu May 12 2016 00:00:00 GMT+0200 (CEST),
value: { title: 'javascript study group' } }
{ key: '4e9007c81c2c50ee373c9d69c94259ad',
time: Thu May 19 2016 00:00:00 GMT+0200 (CEST),
value: { title: 'javascript study group' } }
{ key: '6538b3a92859e99267ad45b15ae6ab1d',
time: Tue May 24 2016 00:00:00 GMT+0200 (CEST),
value: { title: 'open hack' } }
{ key: '4e9007c81c2c50ee373c9d69c94259ad',
time: Thu May 26 2016 00:00:00 GMT+0200 (CEST),
value: { title: 'javascript study group' } }
api
var calendar =
var cal = calendar(db)
Create a new calendar instance cal
from a leveldb instance db
.
cal.add(time, opts, cb)
Add an event given by a free-form string time
which is parsed by
parse-messy-schedule. Optionally:
opts.created
- parse relative to this timeopts.value
- a value to store alongside the time
cb(err, id)
fires with the event id
.
var stream = cal.query(opts, cb)
Return a readable stream of all events between opts.gt
and opts.lt
,
including all instances of recurring events.
If cb
is given, cb(err, results)
fires with an array of all the results
.
cal.get(id, cb)
Read a document by its id
. cb(err, doc)
fires with the doc
:
doc.time
- time stringdoc.value
- supplementary valuedoc.created
- time string parsed relative to this time
cal.remove(id, cb)
Remove a document by its id
.
cal.prepare(time, opts, cb)
Like add, but do not write to the database. Instead, prepare()
returns an
object res
that you can use to batch insert into the database yourself:
res.id
- id of the eventres.batch
- array of documents to batch insert into the database
Optionally specify:
opts.created
- parse relative to this timeopts.value
- a value to store alongside the timeopts.type
-'put'
(default) or'del'
The batch data is more useful if you wish to insert additional documents atomically along with the event data.
install
npm install calendar-db
license
BSD