Git Product home page Git Product logo

chicken-sublevel's Introduction

chicken-sublevel

Provides easy namespacing of keys inside a single LevelDB database. This is an implementation of the level API.

Example use

(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

(sublevel db prefix)

Wraps a level implementation with namespaced access. Keys are generated by joining name space strings with the null character.

expand-sublevels

(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.

;; 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"))

chicken-sublevel's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.