A Clojure library designed to store blob files.
The rationale behind is to provide a standard API to store, read and delete blob files, independently of the storage used.
Intended to be a companion for Datomic, given the lack of support for blob files:
When is Datomic not a good fit?
Datomic is not a good fit if you need unlimited write scalability, or have data with a high update churn rate (e.g. counters). And, at present, Datomic does not have support for BLOBs. faq
Supported storages:
Planned:
We consider a blob one of the following types:
(ns blob-storage.api)
(defprotocol BlobStorage
(store! [service blob opts]
"Adds a new blob to the database")
(update! [service id blob]
"Updates a blob from the database")
(del! [service id]
"Delete a blob from the database")
(blob [service id]
"Retrieves a blob given its id")
(drop-schema! [service]
"Drops the schema")
(init-schema! [service]
"Initializes schema"))
(def db-uri (or (System/getenv "DATABASE_URL")
"postgresql://postgres:postgres@localhost:5432/blobs"))
(require '[blob-storage.postgres :as p])
(require '[blob-storage.api :as api])
(def service (p/make db-uri))
(api/init-schema! service)
(require '[blob-storage.api :as api])
(api/store! service
(byte-array [(byte 0) (byte 1) (byte 2)]))
;; "d69b8dc8-53f7-4d67-b71a-8cbd4d125e81"
(require '[blob-storage.api :as api])
(api/update! service
"d69b8dc8-53f7-4d67-b71a-8cbd4d125e81"
(byte-array [(byte 0)]))
;; "d69b8dc8-53f7-4d67-b71a-8cbd4d125e81"
(require '[blob-storage.api :as api])
(api/blob service "d69b8dc8-53f7-4d67-b71a-8cbd4d125e81")
;; {:id d69b8dc8-53f7-4d67-b71a-8cbd4d125e81,
;; :blob #object[[B 0x4c2bf85e [B@4c2bf85e],
;; :created_at #inst "2015-09-14T14:01:15.049787000-00:00",
;; :updated_at #inst "2015-09-14T15:04:20.061402000-00:00"}
(require '[blob-storage.api :as api])
(api/del! service "d69b8dc8-53f7-4d67-b71a-8cbd4d125e81")
(require '[blob-storage.api :as api])
(api/store! service (clojure.java.io/input-stream "/some/file.txt"))
;; "d69b8dc8-53f7-4d67-b71a-8cbd4d125e81"
$ export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/blobs_test" && lein test
$ set -x DATABASE_URL "postgresql://postgres:postgres@localhost:5432/blobs_test"; lein test
Copyright © 2015 Intception
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close