Fork me on GitHub
#clojure
<
2023-12-30
>
joshcho06:12:05

I want a really simple way to persist clojure maps, without learning database semantics. The main use case is prototyping and small projects. What is the best library/way to do this?

practicalli-johnny07:12:23

Write Clojure maps to an .edn file, no extra library required.

👍 10
vemv11:12:46

...in combination with add-watch for reactivity :)

borkdude16:12:42

it also depends what combination of ACID you want

🔥 1
seancorfield17:12:23

> without learning database semantics I'm curious what you mean by this @U6D1FU8F2? The basics of storing and retrieving hash maps in/from a database are straightforward via https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.3.909/doc/getting-started/friendly-sql-functions and you can use a local on-disk database without needing to install or run a separate process (H2, SQLite, Derby, etc). The only thing you need to do upfront is create tables for the data to live in -- is that the "database semantics" you want to avoid learning?

joshcho23:12:23

@U04V70XH6 yeah, I am looking for the simplest way to go from an in-memory clojure map to making that persistent, for smaller projects. conceptually working with normal clojure functions (like get, assoc, etc.) is simple and consistent, albeit not scalable

daveliepmann15:01:28

another option in this space is https://github.com/jackrusher/spicerack

❤️ 1
Noah Bogart19:12:13

i finally found a usecase for iteration. very cool but dang this is a hard function to use correctly lol

1
jjttjj20:12:37

I've been a big fan of it, but during dev time I always wrap it in an education with a map-indexed transducer that throws after some number of iterations, because I always end up accidentally in an infinite loop hammering the endpoint I'm hitting

😅 1
Noah Bogart20:12:56

I just do (take 1) or (take 5) as i need to when developing lol

ghadi20:12:25

what was the use case ?

Noah Bogart21:12:01

Getting all of my scrobbles from the http://last.fm api for the year with their paginated endpoint

cjohansen21:12:38

Is it possible to make a lazy single value? E.g. something a little less clunky than:

(def val (map compute-value [:my-single-input]))

(first val)

cjohansen21:12:31

Looks like exactly what I need!