Where does Deno keep the `localStorage` SQLite file?
Asked Answered
E

2

6

I've just read through the Web API's from the Deno docs and seems like localStorage is implemented as a persisted SQLite and sessionStorage is implemented as a in-memory SQLite.

Whenever passing no --location argument, where in my filesystem can I find the SQLite DB?

Ecphonesis answered 8/10, 2022 at 8:21 Comment(4)
May be you should be asking on superuser.com?Galligan
The question is not about programming or an algorithm. You are asking merely about a file location for a particular software.Galligan
@Galligan Deno is a JS runtime, clearly seems programming related to me (precedence: #5927172)Crespi
While I could still argue against, the sqlite tag is definitely irrelevant. Just because the target file has a particular format, does not justify the tag. The question is merely about the location of the file, and its contents is irrelevant here.Galligan
K
7

By running deno info you get the value for Origin storage, which is where localStorage data is saved. (See Where can I see deno downloaded packages? for more info)

$ deno info
DENO_DIR location: /home/foo/.cache/deno
Remote modules cache: /home/foo/.cache/deno/deps
npm modules cache: /home/foo/.cache/deno/npm
Emitted modules cache: /home/foo/.cache/deno/gen
Language server registries cache: /home/foo/.cache/deno/registries
Origin storage: /home/foo/.cache/deno/location_data

Inside .cache/deno/location_data you'll see different folders for different storages depending on the --location flag.


Run the following Deno script:

localStorage.setItem("myDemo", "Deno App");

Now you'll see a folder inside location_data

# Replace with the location specified in <Origin Storage>
ls ~/.cache/deno/location_data/

You'll get something like this:

03c0fe5beae8096bc7bdbe2232281947d85e38f4f95f6397559f30b670cb8549/

If you enter that folder you'll get three files:

local_storage  local_storage-shm  local_storage-wal

You can load local_storage file into sqlite3 and see the data:

# inside that folder
sqlite3 local_storage
select * from data;

The output will be the data saved by setItem

myDemo|Deno App

Have in mind that this is for internal use

Kiona answered 8/10, 2022 at 10:45 Comment(1)
This also works if you are looking for the Deno KV local database files (created when you do await Deno.openKv()), they will be in this same location.Floydflss
F
1

According to Environment variables | Set Up Your Environment | Manual | Deno, this information is stored in DENO_DIR:

  • DENO_DIR - this will set the directory where cached information from the CLI is stored. This includes items like cached remote modules, cached transpiled modules, language server cache information and persisted data from local storage. This defaults to the operating systems default cache location and then under the deno path.

The default directory is:

  • On Linux/Redox: $XDG_CACHE_HOME/deno or $HOME/.cache/deno
  • On Windows: %LOCALAPPDATA%/deno (%LOCALAPPDATA% = FOLDERID_LocalAppData)
  • On macOS: $HOME/Library/Caches/deno
  • If something fails, it falls back to $HOME/.deno
Flammable answered 8/10, 2022 at 10:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.