What is the easiest way to save maps / structures in Clojure?

The obvious way is to load JDBC support from Clojure Contrib and write some function to translate the map / structure into a table. One of the disadvantages of this is that it is not very flexible; changes in your structure will require DDL changes. This implies either recording DDL (hard) generation or manual coding (drilling).

What alternatives exist? Answers should be ACID, exclude serialization to a file, etc.

+7
clojure persistence
source share
6 answers

Using CouchDB's Java-client lib and clojure.contrib.json.read/write works pretty well for me. However, CouchDB compatibility guarantees may not be strong enough for your purposes.

+5
source share

FleetDB is a database implemented in Clojure. It has a very natural syntax for working with maps / structures, for example. to insert:

 (client ["insert" "accounts" {"id" 1, "owner" "Eve", "credits" 100}]) 

Then select

 (client ["select" "accounts" {"where" ["=" "id" 1]}]) 

http://fleetdb.org/

+9
source share

One option for persistent maps in Clojure, which still uses a relationship database, is to store map data in an opaque blob. If you need the ability to search for records, you can store indexes in separate tables. For example, you can read how FriendFeed stores non-standard data on top of MySQL - http://bret.appspot.com/entry/how-friendfeed-uses-mysql

Another option is to use the Entity-Attribute-Value (EAV) attribute model to store data in the database. You can learn more about EAV on Wikipedia (I would post a link, but I am a new user and can only post one link).

Another option is to use BerkeleyDB for Java, a native Java solution that provides ACID and write-level locks. (The same problem with link placement).

+7
source share

Clj-record is an implementation of an active record in clojure that may interest you.

+2
source share

You can try one of the Java-based databases, such as Neo4J . It might be easy to code the hashmap interface to make it transparent enough.

+2
source share

MongoDB and its congomongo framework (lein: [congomongo "0.1.3-SNAPSHOT"]) works for me. It's incredibly nice with schemaless databases, and congomongo is pretty easy to get along with. MongoDB adds a _id field in each document to identify it, and there is good transparency between clojure cards and mongo cards.

https://github.com/somnium/congomongo

EDIT: Today I would not use MongoDB. I suggest you take advantage of transit . I would use JSON if the backend (Postgres etc.) supports it or msgpack encoding if you want to have a more compact binary encoding.

+1
source share

All Articles