Fork me on GitHub

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?


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


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


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


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


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?


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.


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


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


makes sense! Thanks again