len
Calendar database for resource bookings using leveldb
installation
$ npm install len
usage
You create a len database by passing in an existing leveldb - this can also be a sub-level
var len = ;var level = ; // create a new leveldb - this can also be a sub-levelvar leveldb = ; // create a new lem store using the leveldbvar lendb = ;
A booking represents a resource being used for a period of time.
Here we create a booking for bob the mechanic:
// start at 9.30var start = '04/03/14 09:30:00';// end at 13.30var end = '04/03/14 13:30:00'; lendb
We can ask len about bookings for all mechanics in a particular month:
var through = ;var start = '03/01/2014';var end = '04/01/2014'; var bookings_in_month = 0; lendb
resource tree
Resources are created using paths and this can be a useful way to get booking reports at various layers.
For example - imagine we have a team that does some projects - we want to be able to ask the following questions:
- the start and end point of one project
- an array of bookings for one project
- an array of bookings for all projects
- an array of bookings between certain points for all projects
This can be done using the paths you give to resources - if we create resources with the following paths:
- team.alpha.project.1
- team.alpha.project.2
queries
Then we can ask for the start and end for one project:
lendb
get a readstream of bookings:
// bookings for one projectlendb // bookings for one team's projectslendb
get a readstream of bookings withing a time period
var start = '03/04/14 09:30:00';var end = '03/04/14 13:30:00'; lendb
api
len(leveldb);
Create a new len database from the provided leveldb. This can be a level-sublevel so you can partition len into an existing database.
var len = ;var level = ; var leveldb = ;var lendb = ;
lendb.loadBooking(resourcepath, bookingid, callback)
Fetch a booking record using the resourcepath and booking id:
lendb
lendb.saveBooking(resourcepath, booking, callback)
Insert/update a booking into the schedule for a resource.
booking is an object:
id: 0 // the id of the booking you are saving - this is auto-created is left blankstart: Date // the start timestamp of the bookingend: Date // the end timestamp of the bookingmeta: // an object with anything you like for the booking meta-datacustomer:12comments:'apples'
The start and end timestamps are required - the meta object is converted to a JSON string and is returned in the 'meta' property of bookings.
var start = '03/04/14 09:30:00';var end = '03/04/14 13:30:00'; lendb
lendb.removeBooking(resourcepath, bookingid, callback)
Remove a booking from the schedule
resource
lendb.getRange(resourcepath, [window], callback)
Use this to get the start and end date for bookings in a resource
lendb
You can also pass a window to constrain the results:
lendb
lendb.createBookingStream(resourcepath, [window], callback)
Use this to get an object stream of bookings for a given resource.
var through = ; lendb
You can also query the booking stream using a time-window:
var through = ;var start = '03/01/2014';var end = '04/01/2014'; var bookings_in_month = 0; lendb
the inclusive option controls whether bookings have to start and end inside the time window (true) or if any part of it is in the time window (false)
license
MIT