Fork me on GitHub
#sql
<
2023-01-09
>
Hanan Benzion07:01:50

Hi, I’m working with SQLite on my project and using jdbc.next. I want to load to my SQLite DB a JSON file with a complex and not strict structure. From what I understood it’s not really possible with jdbc.next as I need to well define the structure when I create the table. While searching for a solution I came across https://sqlite-utils.datasette.io/en/stable/cli.html#inserting-json-data, but I couldn’t find a Clojure implementation. Does anyone know what is the best way to tackle this thing with Clojure? Thanks

Hanan Benzion07:01:44

Thanks for the answer. Sorry for the newbie question, but how can I use it in Clojure?

Cora (she/her)13:01:12

just create text fields in your database and then convert to json before writing to the db and parse json after reading from the db.

Hanan Benzion14:01:24

The main task that I have is actually taking a JSON file with multiple objects that have different (partially common) scheme and add all the file to a table in my SQLite database.

Cora (she/her)14:01:24

you could put the common fields into columns and write the rest into a text field as json, then?

Cora (she/her)14:01:48

and then use the functions I linked when you need to query on json