friar-tuck is a Clojure(Script) library to help you solve the same problems I had myself.
- MongoDB interface in the JVM via congomongo (java driver)
- TaffyDB interface on the browser
By Louis Rhead - Rhead, Louis. "Bold Robin Hood and His Outlaw Band: Their Famous Exploits in Sherwood Forest". New York: Blue Ribbon Books, 1912., Public Domain, Link
Just as Sam did all the heavy lifting in the background for Frodo without taking enough credit, Friar Tuck helped Robin Hood.
Also, me and Tuck have more in common: we are both meadmakers!
Right now, tuck can help you manage your goodies cellar.
Enough about flavor...
As of now, only cellar.cljc works. It gives you a unified api to use TaffyDB while on the browser/cljs/js (you still need to add taffydb.min.js yourself), or MongoDB while on the server/clj/jvm (via congomongo).
I tried to keep it as simple as possible for new users/learners, if you need advanced features or other databases, I can't implement them right now, but help is welcome!
Why TaffyDB?
- It is a simple and easy to use javascript database.
- It uses HTML5 LocalStorage for persistence.
- It works without callback orgy, just invoke and get results.
- It also runs on NodeJS (as long as you also add the npm package).
Why MongoDB?
- NoSQL
- Easy and simple to use/setup.
- Everyone is using it (maybe because of 2).
- I like green (matches Robin Hood theme).
Why congomongo?
- It worked just right for my past uses, so why not?
I believe docs are straightforward (docstrings, you can see them in the repl calling (doc function)), but examples are never too much:
(ns your-namespace
(:require [tuck.cellar :as tc]))
(def mydb (atom nil))
;; Clojure/JVM/MongoDB
(tc/config-db! {:db mydb :dbname "mydb" :coll "mycoll" :port 8080})
;; ClojureScript/JS/TaffyDB
(tc/config-db! {:db mydb :dbname "mydb"}) ;; no need for :coll or :port
;; Once mydb refers to our database, the api is the same:
(tc/insert! {:db mydb :data {:a "A" "1" [1 2 3] "B" {:b1 1 :b2 2}}})
(tc/insert! {:db mydb :json "{'1':[1,2,3],'a':'A','B':{'b1':1,'b2':2}}"})
(tc/search {:db mydb :query {:a "A"}}) ;; returns the result from querry
(tc/update! {:db mydb :query {:a "A"} :data {:A ["a" "b"]}}) ;; update! actually merges the result with the value of :data key
(tc/delete! {:db mydb :query {:a "A"}})
(tc/replace! {:db mydb :query {:a "A"} :data {"dog" "nice" "yes" [666]}}) ;; replace! deletes the query result and then inserts the value from :data key
Right now, only single result/exact queries were tested.
Copyright © 2017 FIXME
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.