Skip to content

Add support for IndexedDB #1699

Open
Open

Description

@dsseng

It'll be useful to have IndexedDB in Deno.
Related to #1657.

Activity

  1. manyuanrong commented on Feb 14, 2019

    @manyuanrong
    Contributor

    Should we use pure TS implementation or on the Rust side?

  2. manyuanrong commented on Feb 14, 2019

    @manyuanrong
    Contributor
  3. kitsonk commented on Mar 13, 2019

    @kitsonk
    Contributor

    This is really complicated when you dig into it.

    There is no Rust implementation of IndexDB (there is a crate that appears to be squatting, but it really isn't an implementation). Servo does not support IndexedDB, they have a long standing issue to implement. So on the Rust front it is sort of a dead end.

    In Node.js, there are no realistic implementations either. Again there is a package squatting on indexeddb, but it isn't really a good package at all. The one thing that seems to have promise is IndexedDBShim which sits on top of WebSQL, and there are native implementations of WebSQL on Node.js using sqlite3.

    jsdom doesn't implement IndexedDB or WebSQL, though there is this issue talking about implementing the IndexedDB shim mentioned above, I assume requiring the WebSQL implementation. It looks like it is stalled.

    There is also an in memory IndexedDB API written in TypeScript.

    There is what looks like a realistic Rust create for sqlite3.

    So outside of using a C++ implementation, which would be a break in the pattern, the only realistic path I can easily see is that to use the in memory IndexedDB written in TypeScript, which would not give persistent storage, or we could adapt the in memory version and wire it up to a Rust sqlite3 bindings to persist the data.

    I don't think just persisting out to JSON really works, because IndexedDB is a bit more complex than that, it contains concepts like transactions and other database features which is why almost all the browser implementations are based on sqlite3 IIRC.

  4. kitsonk commented on Apr 24, 2020

    @kitsonk
    Contributor

    Just updating this, servo still doesn't have it, and Gecko is looking at refactoring, but it is sqlite3 under the hoods. Here is a the most recent post that lays things out most relevantly: servo/servo#6963 (comment).

    It would be really good to get localStorage/IndexedDB/kv-store in to Deno, IMO.

  5. anlexN commented on May 18, 2020

    @anlexN
  6. kitsonk commented on May 18, 2020

    @kitsonk
    Contributor

    @anlexN your comment is borderline abusive. The issue is well discussed here of how it is a complex issue. Please keep your conversation civil and on-topic.

  7. added
    featnew feature (which has been agreed to/accepted)
    webrelated to Web APIs
    on Nov 5, 2020
  8. changed the title [-]IndexedDB[/-] [+]Add support for IndexedDB[/+] on Nov 5, 2020
  9. jacobbogers commented on Apr 6, 2021

    @jacobbogers

    HI, just exploring deno a bit, i thought (my mental model) is that deno implemented chromium aswell, (so it 100% compatible (as much as possible) with all webapis)

    is the source code of the implementation of indexDB (firefox chrome) open sourced?

  10. kitsonk commented on Apr 6, 2021

    @kitsonk
    Contributor

    @jacobbogers Deno does not implement Chromium, it only implements V8. All the Web APIs need to be implemented independently. Chromium tends to implement these in C++ using the v8 binding to inject objects into the isolate.

    Yes, both Firefox and Chromium are open source and their code is available, but that doesn't make it magically work for Deno.

  11. jacobbogers commented on Apr 7, 2021

    @jacobbogers

    @jacobbogers Deno does not implement Chromium, it only implements V8. All the Web APIs need to be implemented independently. Chromium tends to implement these in C++ using the v8 binding to inject objects into the isolate.

    Yes, both Firefox and Chromium are open source and their code is available, but that doesn't make it magically work for Deno.

    thanks for explaining, well at least if the source is avail (Firefox/Chrome) then we can kindof get some ideas /inspiration how to implement it,

    IndexDB is a tuff nut to crack, it has transactions but has no explicit commit (its weird and ingenious way of doing transactions) this would not be easy to build from scratch.

  12. kitsonk commented on Apr 7, 2021

    @kitsonk
    Contributor

    @jacobbogers we have ideas/inspiration. One of the biggest factors was that we didn't have easy access to the V8 serialize/deserialize routines, which you need to support "structured cloning" which is needed to be able to store objects. We have that now. The other problem is the underlying DB as well as support under Rust. LevelDB (the one Google created and is in Chromium) is a bit of a mess. Firefox and Safari use SQLite as well as Servo looked at SQLite (can't remember how far they got). The biggest problem is the analogues between how Chromium and Firefox operate, and how Deno operates mean that there is very little overlap. For implementing web standards, we have had a lot better luck looking at a JavaScript shim/polyfill and the specification itself, than we have looking at other browser implementations.

    There are the wpt for IndexedDB which helps ensure the standard is implemented correctly, and we now have the wpt integrated into our test process.

  13. brainless commented on May 25, 2021

    @brainless

    Hey everyone just reading the discussions. I think IndexDB for Deno might end up being used in more varied (or larger) ways than in a browser. For example, it is OK to expect data eviction in the browser, but if developers use IndexDB as a persistent backend store (like say SQLite) then the they might want further control of the underlying storage, its space allocation, path, etc.. Ability to backup/restore also comes to mind.

    Maybe my thought process is incorrect, just that I felt it is perhaps a good time to share these now, before we have a ready implementation.

  14. kitsonk commented on May 25, 2021

    @kitsonk
    Contributor

    then the they might want further control of the underlying storage, its space allocation, path, etc..

    Then that isn't IndexedDB, that is a native SQLite plugin.

  15. 27 remaining items

  16. idranme commented on Jul 13, 2023

    @idranme
    Contributor

    @crowlKats I have some interest in implementing this, but I don't want to take something away that you really want to do. If it is okay, should I start from your branch in #14035? Or just cut a fresh branch independent of yours and open a separate PR?

    I'm kind of looking forward to it.

  17. alexgleason commented on Jul 23, 2023

    @alexgleason
    Contributor

    Now that Deno.KV is a thing, would it make sense to make IndexedDB a wrapper around the Deno.KV API instead of yet another SQLite? That way IndexedDB on Deno Deploy would take advantage of FoundationDB, and it would mean improvements to Deno.KV locally (see: #18657) would improve the IndexedDB implementation.

  18. idofilus commented on Mar 31, 2025

    @idofilus

    I needed this support for creating unit testing designed for the browser and tested by deno.
    So this worked for me:

    import { assertEquals } from "@std/assert";
    import { indexedDB } from "npm:fake-indexeddb@6.0.0";
    
    globalThis.indexedDB = indexedDB;
    
    // The actual implementation of the indexedDB APIs 
    import LocalDataSource from "LocalDataSource.ts";
    
    Deno.test(async function LocalDataSourceTest()
    {
        assertEquals(1, 1);
    });
  19. mfulton26 commented on Mar 31, 2025

    @mfulton26

    @idofilus, as far as I know, npm:fake-indexeddb does not persist to disk which is something that would be desired from Deno built-in support. The more Deno runtime works like browser runtimes the easier it is to write universal code and the less APIs there are to learn and code against.

  20. bartlomieju commented on May 3, 2026

    @bartlomieju
    Member

    It's 2026 and most people use some sort of SQLite flavor. We have native support for
    node:sqlite and also Deno.KV which is built on top of SQLite. We're not gonna do IndexedDB after all.

  21. alexgleason commented on May 3, 2026

    @alexgleason
    Contributor

    This is one of the few things in 2026 that could make Deno more appealing than Bun

  22. tracker1 commented on May 4, 2026

    @tracker1

    @bartlomieju I think having IndexedDB is important and should remain as a feature request for browser parity.

    I don't know what it would take to implement either on top of SQLite or via LevelDB, but as a JS/TS engine feature, I think it is a pretty wide miss at this point.

  23. bartlomieju commented on May 4, 2026

    @bartlomieju
    Member

    I'm gonna reopen this for now, but there's a slim chance we will implement this.

    What do people want to use it for anyway?

  24. idofilus commented on May 4, 2026

    @idofilus

    I'm gonna reopen this for now, but there's a slim chance we will implement this.

    What do people want to use it for anyway?

    Another major browser api that can be used in the code designed to run on browsers, with access to the all other of deno apis.
    In my given case provided in this thread, I have a DataSource core class handling database related connection, e.g. mongodb MongoDataSource. Which I also allow the same core class as local storage, e.g. in the browser - this for example will be an offline database, with the option to sync against the remote e.g. mongo.

    Since my server side is in Deno, and having that server side only code e.g. MongoDataSource I have the unit testing in it, now since it's the same DataSource core class, I made the unit testing on that class, and just creating the instances for the other inherited classes, therefore running a unit testing in deno to validate the browser's side LocalDataSource in the same pipeline.

    The more browser apis in deno, the better "shared code" we can have, IndexedDB is quite useful for many use cases where compatibility of the code with the browser is required.

  25. alexgleason commented on May 4, 2026

    @alexgleason
    Contributor

    What do people want to use it for anyway?

    I want to test my browser libraries.

  26. oscarotero commented on May 4, 2026

    @oscarotero
    Contributor

    Having support for IndexDB allows to write code that works on both front and backend and use libraries like Dexie.js or localForage that work on top of indexDB. It does a similar job as Deno.KV, but it's more standard, with more features and a bigger ecosystem. In fact, I think Deno.KV could be a @std library built on top of indexDB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featnew feature (which has been agreed to/accepted)webrelated to Web APIs

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions