datascript

Chase 2022-04-02T16:04:00.222009Z

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?

lilactown 2022-04-02T16:17:11.442469Z

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

lilactown 2022-04-02T16:18:11.990529Z

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

lilactown 2022-04-02T16:19:00.306059Z

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

Chase 2022-04-02T16:29:59.491199Z

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

Chase 2022-04-02T16:33:27.072769Z

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?

lilactown 2022-04-02T16:47:45.493989Z

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.

lilactown 2022-04-02T16:50:10.650409Z

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

lilactown 2022-04-02T16:51:11.643909Z

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

Chase 2022-04-02T16:51:58.691339Z

makes sense! Thanks again