Skip to content

Instantly share code, notes, and snippets.

@JustinTulloss
Created March 22, 2009 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JustinTulloss/83113 to your computer and use it in GitHub Desktop.
Save JustinTulloss/83113 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