Skip to content
pgte edited this page Dec 30, 2010 · 8 revisions

Key-value store.

Writes into a collection.

key_map.put(key, value, callback)

Stores an object.

  • key: key by which you can retrieve the object afterwards
  • value: the object you want to store
  • callback(err, pos, length): when put is done or an error occurs. If an error occurs, first argument will have the error object. If not, second argument will have the position of the underlying collection and the occupied length.

key_map.get(key, callback)

Retrieves an object by key.

  • key
  • callback(err, value) : when object is retrieved, with error on first argument or value on the second argument.

key_map.getAtPos(pos, length, callback)

Retrieves an object by position and length.

  • pos: the position of the object on the underlying collection.
  • length: the length of the object on the underlying collection.
  • callback(err, key, value) : when object is retrieved, with error on first argument or value on the second argument.

key_map.startStream(filter_function, callback)

Creates a stream based on the filter function. Callback will be called every time there is a "put" that matches the filter. Returns a handler that can be used to stop the stream.

  • filter_function(key, value)
  • callback(key, value)

key_map.stopStream(handler)

Stops a stream given a handler earlier returned by startStream();

key_map.putAtPos(key, value, pos, callback)

Stores an object.

  • key: key by which you can retrieve the object afterwards
  • value: the object you want to store
  • pos: the position you want it written into the underlying collection
  • callback(err, pos, length): when put is done or an error occurs. If an error occurs, first argument will have the error object. If not, second argument will have the position of the underlying collection and the occupied length.

key_map.clear(callback)

Removes all elements from the underlaying collection, removing all elements from this key map too.

  • callback(err): called when clearing finishes or there is an error (first argument).

key_map.end(callback)

Ends this key_map, also ending the underlying collection.

  • callback(err): called when ending finishes or there is an error (first argument).

key_map.rename(callback)

Renames the file for this key_map.

  • callback(err): called when renaming finishes or there is an error (first argument).

Indexes

key_map.addIndex (name, [options], transform_function, callback)

Adds an index to the key_map.

  • name: name of the index (string)
  • options: object with options. if options.ordered, will instantiate an ordered index. Also see specific options to specific index types.
  • callback(err, index): called when adding index finishes or an error occurs. Second argument is the index if no error occurred.

key_map.dropIndex (name, callback)

Drops an index from the key_map.

  • name: name of the index (string) to remove
  • callback(err): called when dropping index finishes or an error occurs

key_map.getIndex (name)

Returns the index under this name or undefined if not found.

  • name: name of the index (string)

key_map.filter (index, filter_function, callback, null_on_not_found)

Goes through the index and calls filter_function on it, invoking callback when filter_function returns true.

  • index: index object or name of the index
  • filter_function (record): return true when you want the passed-in index record selected.
  • callback(err, key, value): invoked when there is an error or a record is selected.
  • null_on_not_found: if true, callback(null, null) will be invoked if no record is yielded

key_map.range (index, start, end, callback)

Selects all the records which indexed value >= start and <= end.

Only available for ordered indexes

  • index: index object or name of the index
  • start: start at value
  • end: end at value
  • callback: invoked when there is an error or for each selected record.

key_map.countFilter (index, filter_function, callback)

Gets the count of the selected records via filter_function.

  • index: index object or name of the index
  • filter_function (record): return true when you want the passed-in index record selected.
  • callback(err, count): invoked when there is an error or a record is selected.

key_map.indexMatch (index, value, callback)

Calls callback for every element on the index == value.

  • index: index object or name of the index
  • value: the value you want to match against.
  • callback (err, key, value): invoked when there is an error or a record is matched.