# calendar-db

> store and query recurring and one-time events

Latest version **1.2.1** (published 2016-06-17) · BSD license · 0 weekly downloads

## Install

```sh
npm install calendar-db
pnpm add calendar-db
yarn add calendar-db
bun add calendar-db
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2016-06-17 |
| First published | 2016-05-23 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | substack |
| Maintainers | substack |
| Keywords | calendar, database |

## Links

- npm: https://www.npmjs.com/package/calendar-db
- Repository: https://github.com/substack/calendar-db
- Homepage: https://github.com/substack/calendar-db#readme
- Issues: https://github.com/substack/calendar-db/issues
- npm.io page: https://npm.io/package/calendar-db

## Dependencies (8)

- [defined](https://npm.io/package/defined.md) ^1.0.0
- [strftime](https://npm.io/package/strftime.md) ^0.9.2
- [through2](https://npm.io/package/through2.md) ^2.0.1
- [randombytes](https://npm.io/package/randombytes.md) ^2.0.3
- [collect-stream](https://npm.io/package/collect-stream.md) ^1.1.1
- [readable-stream](https://npm.io/package/readable-stream.md) ^2.1.3
- [levelup-defaults](https://npm.io/package/levelup-defaults.md) ^1.0.2
- [parse-messy-schedule](https://npm.io/package/parse-messy-schedule.md) ^2.0.1

## Recent versions

- 1.2.1 (latest) — 2016-06-17
- 1.2.0 — 2016-05-25
- 1.1.0 — 2016-05-24
- 1.0.2 — 2016-05-23
- 1.0.1 — 2016-05-23
- 1.0.0 — 2016-05-23

## README

# calendar-db

store and query recurring and one-time events

# example

## add

``` js
var level = require('level')
var db = level('/tmp/cal.db')
var calendar = require('calendar-db')

var cal = calendar(db)
var time = process.argv[2]
var opts = {
  value: { title: process.argv[3] }
}
cal.add(time, opts, function (err, id) {
  if (err) console.error(err)
  else console.log(id)
})
```

```
$ 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

``` js
var level = require('level')
var db = level('/tmp/cal.db')

var minimist = require('minimist')
var argv = minimist(process.argv.slice(2))

var calendar = require('calendar-db')
var cal = calendar(db)

cal.query(argv, function (err, results) {
  if (err) return console.error(err)
  results.forEach(function (r) { console.log(r) })
})
```

```
$ 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

``` js
var calendar = require('calendar-db')
```

## var cal = calendar(db)

Create a new calendar instance `cal` from a [leveldb][1] instance `db`.

[1]: https://npmjs.com/package/level

## cal.add(time, opts, cb)

Add an event given by a free-form string `time` which is parsed by
[parse-messy-schedule][2]. Optionally:

* `opts.created` - parse relative to this time
* `opts.value` - a value to store alongside the time

`cb(err, id)` fires with the event `id`.

[2]: https://npmjs.com/package/parse-messy-schedule

## 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 string
* `doc.value` - supplementary value
* `doc.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 event
* `res.batch` - array of documents to batch insert into the database

Optionally specify:

* `opts.created` - parse relative to this time
* `opts.value` - a value to store alongside the time
* `opts.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

---
_Source: https://npm.io/package/calendar-db · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
