https://github.com/caolan/chicken-sublevel
Namespaced access to leveldb implementations
https://github.com/caolan/chicken-sublevel
Last synced: 5 months ago
JSON representation
Namespaced access to leveldb implementations
- Host: GitHub
- URL: https://github.com/caolan/chicken-sublevel
- Owner: caolan
- Created: 2014-07-27T11:20:38.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2016-07-05T07:39:59.000Z (almost 10 years ago)
- Last Synced: 2025-04-07T13:51:16.323Z (about 1 year ago)
- Language: Scheme
- Size: 17.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# chicken-sublevel
Provides easy namespacing of keys inside a single LevelDB database. This is
an implementation of the [level](https://github.com/caolan/chicken-level)
API.
## Example use
```scheme
(use level leveldb sublevel lazy-seq)
(define db (open-db "./my-database"))
(define books (sublevel db '("books")))
(define cds (sublevel db '("music" "cds")))
(db-put books "book1" "foo")
(db-put books "book2" "bar")
(lazy-seq->list (db-stream books)) ;; => (("book1" "foo") ("book2" "bar"))
(lazy-seq->list (db-stream cds)) ;; => ()
```
## API
### sublevel
```scheme
(sublevel db prefix)
```
Wraps a level implementation with namespaced access. Keys are generated by
joining name space strings with the `null` character.
### expand-sublevels
```scheme
(expand-sublevels root db ops)
```
Takes a list of operations (as you would pass to the db-batch procedure)
and expands the keys in the list to match the full key that would be
written for the provdided sublevel(s). The key namespaces between 'root'
and 'db' are expanded. The 'root' argument can be any level
implementation (eg, a raw leveldb object or another sublevel).
This can be useful if you find yourself needing to apply a transaction
across multiple sublevels. You can use this for each sublevel to build the
final batch operations list then use db-batch on the underlying resource.
```scheme
;; Example
(define db (open-db "./my-database"))
(define sub1 (sublevel db '("one")))
(define sub2 (sublevel sub1 '("two")))
(expand-sublevels db sub2 '((put "example" "value")))
;; => '((put "one\x00two\x00example" "value"))
(expand-sublevels sub1 sub2 '((put "example" "value")))
;; => '((put "two\x00example" "value"))
```