Skip to content

Instantly share code, notes, and snippets.

@jefftriplett
Forked from JustinTulloss/gist:83113
Created May 7, 2009 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jefftriplett/107941 to your computer and use it in GitHub Desktop.
Save jefftriplett/107941 to your computer and use it in GitHub Desktop.
; A wrapper to access Tokyo Cabinet from clojure
(ns tokyo-cabinet
; exclude symbols we'll use in our API
(:refer-clojure :exclude [use get]))
(declare *db*)
(defn get [key] (.get *db* key))
(defn put [key value] (.put *db* key value))
(defmacro use [filename & body]
(import '(tokyocabinet HDB))
`(with-open [hdb# (HDB.)]
(.open hdb# ~filename (bit-or HDB/OWRITER HDB/OCREAT))
(binding [*db* hdb#]
(do ~@body))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment