Search code examples
sqlitelocal-storagefilesystemsdeno

Where does Deno keep the `localStorage` SQLite file?


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?


Solution

  • 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