我正在尝试在 ring/compojure 应用程序中设置 LevelDB,并寻找一种惯用的方式来将打开的数据库描述符访问到每个请求中。
例如:
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Opening LevelDB file in db/main")
(with-open [main-db (db/open "db/main")]
(println "Running server on port 3000")
(run-jetty #'web/app {:port 3000})))
您如何将main-db
描述符访问到请求处理程序中?
IE。:
(defroutes handler
(GET "/test" []
(db/put main-db (.getBytes "testKey2") (.getBytes "testValue2"))
"<h1>Hello World</h1>")
PS:我正在使用 Sedward 的 leveldb-clj 库并将其打包成 clojar:https ://clojars.org/org.clojars.aircart/leveldb-clj