Fork me on GitHub
#datascript
<
2022-04-02
>
Chase16:04:00

I was curious about something. I was exploring clj db options for my own app ideas and coincidentally also checking out these new note taking apps written in clj/cljs like Roam, Logseq, and Athens. The datascript readme mentions that they all use datascript for their db needs but in reading the docs I feel like it also says datascript is "ephemeral" so when you close the browser, you lose all that db data. But obviously this isn't happening in those apps because you can access all your old notes, right? Can you please clear up my misunderstanding here as my db knowledge is still very beginner level. Can I use datascript in a web app where I need to let users access data they saved in previous logins or whatever?

lilactown16:04:11

there are plenty of ways to persist a datascript db yourself. datascript doesn't have a built in way of doing this, though

lilactown16:04:11

for instance, you could send the data to a backend and store it in a SQL database, and when the user loads the page you send them all their up to date notes data that gets loaded into datascript in their browser

lilactown16:04:00

or you could serialize the datascript db to a string and store it in local storage, as long as it's not too big, so that the user can access it offline

Chase16:04:59

Ahh ok, that clears up what is happening here and what is possible. Thanks so much

Chase16:04:27

How would you "go" from Datascript (datalog?) to SQL? Is it something like going from datascript to clj data structure and then clj datastructure to SQL with something like hugsql or honeysql?

lilactown16:04:45

I would first model my domain as entities, then figure out the best way to store those entities in datascript and the best way to store those entities in a SQL db. then I would create functions that would take information and store it the right way in each location.

lilactown16:04:10

then when e.g. a user creates a new note in the local app, you send a request to an API that would store the data in a SQL db, and on success take the same data and store it locally in the datascript db

lilactown16:04:11

when the user loads the page, you send a request to the API to get the users notes from the SQL db, and take the result and store it in the datascript db

Chase16:04:58

makes sense! Thanks again