4.0.11 • Published 3 months ago

dexie v4.0.11

Weekly downloads
81,311
License
Apache-2.0
Repository
github
Last release
3 months ago

Dexie.js

NPM Version Build Status

Dexie.js is a wrapper library for indexedDB - the standard database in the browser. https://dexie.org.

Why Dexie.js?

IndexedDB is the portable database for all browser engines. Dexie.js makes it fun and easy to work with.

But also:

  • Dexie.js is widely used by 100,000 of web sites, apps and other projects and supports all browsers, Electron for Desktop apps, Capacitor for iOS / Android apps and of course pure PWAs.
  • Dexie.js works around bugs in the IndexedDB implementations, giving a more stable user experience.
  • It's an easy step to make it sync.

Hello World

<!DOCTYPE html>
<html>
  <head>
    <script src="https://unpkg.com/dexie/dist/dexie.js"></script>
    <script>

      //
      // Declare Database
      //
      const db = new Dexie('FriendDatabase');
      db.version(1).stores({
        friends: '++id, age'
      });

      //
      // Play with it
      //
      db.friends.add({ name: 'Alice', age: 21 }).then(() => {
        return db.friends
          .where('age')
          .below(30)
          .toArray();
      }).then(youngFriends => {
        alert (`My young friends: ${JSON.stringify(youngFriends)}`);
      }).catch (e => {
        alert(`Oops: ${e}`);
      });

    </script>
  </head>
</html>

Yes, it's that simple. Read the docs to get into the details.

Hello World (for modern browsers)

All modern browsers support ES modules and top-level awaits. No transipler needed. Here's the previous example in a modern flavour:

<!DOCTYPE html>
<html>
  <head>
    <script type="module">
      // Import Dexie
      import { Dexie } from 'https://unpkg.com/dexie/dist/modern/dexie.mjs';

      //
      // Declare Database
      //
      const db = new Dexie('FriendDatabase');
      db.version(1).stores({
        friends: '++id, age'
      });

      //
      // Play with it
      //
      try {
        await db.friends.add({ name: 'Alice', age: 21 });

        const youngFriends = await db.friends
            .where('age')
            .below(30)
            .toArray();

        alert(`My young friends: ${JSON.stringify(youngFriends)}`);
      } catch (e) {
        alert(`Oops: ${e}`);
      }
    </script>
  </head>
</html>

Hello World (React + Typescript)

Real-world apps are often built using components in various frameworks. Here's a version of Hello World written for React and Typescript. There are also links below this sample to more tutorials for different frameworks...

import React from 'react';
import { Dexie, type EntityTable } from 'dexie';
import { useLiveQuery } from 'dexie-react-hooks';

// Typing for your entities (hint is to move this to its own module)
export interface Friend {
  id: number;
  name: string;
  age: number;
}

// Database declaration (move this to its own module also)
export const db = new Dexie('FriendDatabase') as Dexie & {
  friends: EntityTable<Friend, 'id'>;
};
db.version(1).stores({
  friends: '++id, age',
});

// Component:
export function MyDexieReactComponent() {
  const youngFriends = useLiveQuery(() =>
    db.friends
      .where('age')
      .below(30)
      .toArray()
  );

  return (
    <>
      <h3>My young friends</h3>
      <ul>
        {youngFriends?.map((f) => (
          <li key={f.id}>
            Name: {f.name}, Age: {f.age}
          </li>
        ))}
      </ul>
      <button
        onClick={() => {
          db.friends.add({ name: 'Alice', age: 21 });
        }}
      >
        Add another friend
      </button>
    </>
  );
}

Tutorials for React, Svelte, Vue, Angular and vanilla JS

API Reference

Samples

Performance

Dexie has kick-ass performance. Its bulk methods take advantage of a lesser-known feature in IndexedDB that makes it possible to store stuff without listening to every onsuccess event. This speeds up the performance to a maximum.

Supported operations

above(key): Collection;
aboveOrEqual(key): Collection;
add(item, key?): Promise;
and(filter: (x) => boolean): Collection;
anyOf(keys[]): Collection;
anyOfIgnoreCase(keys: string[]): Collection;
below(key): Collection;
belowOrEqual(key): Collection;
between(lower, upper, includeLower?, includeUpper?): Collection;
bulkAdd(items: Array): Promise;
bulkDelete(keys: Array): Promise;
bulkPut(items: Array): Promise;
clear(): Promise;
count(): Promise;
delete(key): Promise;
distinct(): Collection;
each(callback: (obj) => any): Promise;
eachKey(callback: (key) => any): Promise;
eachPrimaryKey(callback: (key) => any): Promise;
eachUniqueKey(callback: (key) => any): Promise;
equals(key): Collection;
equalsIgnoreCase(key): Collection;
filter(fn: (obj) => boolean): Collection;
first(): Promise;
get(key): Promise;
inAnyRange(ranges): Collection;
keys(): Promise;
last(): Promise;
limit(n: number): Collection;
modify(changeCallback: (obj: T, ctx:{value: T}) => void): Promise;
modify(changes: { [keyPath: string]: any } ): Promise;
noneOf(keys: Array): Collection;
notEqual(key): Collection;
offset(n: number): Collection;
or(indexOrPrimayKey: string): WhereClause;
orderBy(index: string): Collection;
primaryKeys(): Promise;
put(item: T, key?: Key): Promise;
reverse(): Collection;
sortBy(keyPath: string): Promise;
startsWith(key: string): Collection;
startsWithAnyOf(prefixes: string[]): Collection;
startsWithAnyOfIgnoreCase(prefixes: string[]): Collection;
startsWithIgnoreCase(key: string): Collection;
toArray(): Promise;
toCollection(): Collection;
uniqueKeys(): Promise;
until(filter: (value) => boolean, includeStopEntry?: boolean): Collection;
update(key: Key, changes: { [keyPath: string]: any }): Promise;

This is a mix of methods from WhereClause, Table and Collection. Dive into the API reference to see the details.

Dexie Cloud

Dexie Cloud is a commercial offering that can be used as an add-on to Dexie.js. It syncs a Dexie database with a server and enables developers to build apps without having to care about backend or database layer else than the frontend code with Dexie.js as the sole database layer.

Source for a sample Dexie Cloud app: Dexie Cloud To-do app

See the sample Dexie Cloud app in action: https://dexie.github.io/Dexie.js/dexie-cloud-todo-app/

Samples

https://dexie.org/docs/Samples

https://github.com/dexie/Dexie.js/tree/master/samples

Knowledge Base

https://dexie.org/docs/Questions-and-Answers

Website

https://dexie.org

Install via npm

npm install dexie

Download

For those who don't like package managers, here's the download links:

UMD (for legacy script includes as well as commonjs require):

https://unpkg.com/dexie@latest/dist/dexie.min.js

https://unpkg.com/dexie@latest/dist/dexie.min.js.map

Modern (ES module):

https://unpkg.com/dexie@latest/dist/modern/dexie.min.mjs

https://unpkg.com/dexie@latest/dist/modern/dexie.min.mjs.map

Typings:

https://unpkg.com/dexie@latest/dist/dexie.d.ts

Contributing

See CONTRIBUTING.md

Build

pnpm install
pnpm run build

Test

pnpm test

Watch

pnpm run watch

Browser testing via LAMDBATEST

@web-client/plugin-component-vue@ben-ryder/lfb-toolkit@arcaela/arcaela-jsrclinktestsmt-trend@zentek/zenfieldflintlia-script@voodux/voodux@tuist/preferences@pawi/preferences@liuli-moe/web-logger-storage-indexeddb@gui-one/commonng-ezbitsvelte-petit-libsconsole-core-portal-corehimaindus-trend@shubhamy/blendedhamaren_test_packagehamaren_test_parcelref-uieoapi-corekderno-editorpwa-startercra-template-pwa-starterskill-f3@infinitebrahmanuniverse/nolb-dex@datagrok/molecular-liability-browser@gratico/fsco-cc-componentss-formbuilderngx-albeom-libkkxxx@everything-registry/sub-chunk-1474obsidian-clever-searchweb_log_pluginbuzzmsg-test@owlprotocol/crud-redux@owlprotocol/web3-redux@web-ptp-client/plugin-component-vueaminhp93-componentstaki-popups-servicetareassync-clientsync3k-clientsystemjs-transpile-cachetemporalaboresvelte-nostrsvelte-storageterminal-in-react-pseudo-file-system-pluginterrain-navigatortest-fdtwiz-cloud-renderwire-webapp-cryptoboxwho-is-hiring-dashboardwerbas-connectorwincardvua-crudvue-idbvue-idb-multiversionwebapp-appswebapp-basewed-demowrappex-localwordpress-api-wcxd_websocketxmluiteams_im_uisuperteamstest123-1test123-2test-rxdbtest-zk-chat-clienttestconnect-ordkittheia-monitorthree-jarvisvooduxvalle-web-client-mvpvartistevitra-web-trans@dorring/sdk@doctorassistant/daai-badge@doctorassistant/daai-component@communityboss/browser-utils@cwrc/leafwriter@cwrc/leafwriter-storage-service@cwrc/leafwriter-validator@consolecore/sherpa-portal-core@dinofe/xt-core@darkalienlord/dexie@demox-labs/miden-sdk@cakev/sdk@bunred/bunadmin@blairmacintyre/web-layer-blair@pratico/data@rozbehsharahi/file-storejennifer5-frontendispiredb.jsjuepeiscm-antd-repack
4.1.0-beta.43

3 months ago

4.0.11

3 months ago

4.1.0-alpha.23

5 months ago

4.0.10

5 months ago

4.0.9

6 months ago

4.1.0-alpha.12

6 months ago

4.1.0-alpha.8

6 months ago

4.1.0-alpha.7

6 months ago

4.1.0-alpha.6

6 months ago

4.1.0-alpha.5

6 months ago

4.1.0-alpha.4

6 months ago

4.1.0-alpha.3

7 months ago

4.1.0-alpha.2

7 months ago

4.0.9-alpha.1

8 months ago

4.0.8

10 months ago

4.0.5

11 months ago

4.0.7

11 months ago

4.0.4

1 year ago

4.0.3

1 year ago

4.0.2

1 year ago

4.0.1

1 year ago

4.0.1-rc.1

1 year ago

3.2.7

1 year ago

4.0.1-beta.12

1 year ago

4.0.1-beta.14

1 year ago

4.0.1-beta.13

1 year ago

4.0.1-beta.11

1 year ago

3.2.6

1 year ago

4.0.1-beta.10

1 year ago

3.2.5

1 year ago

4.0.1-beta.9

1 year ago

4.0.1-beta.8

1 year ago

4.0.1-beta.7

1 year ago

4.0.1-beta.6

1 year ago

4.0.1-beta.5

1 year ago

4.0.1-alpha.25

2 years ago

4.0.1-alpha.26

2 years ago

4.0.1-alpha.27

2 years ago

4.0.1-beta.4

1 year ago

4.0.1-beta.2

1 year ago

4.0.1-beta.3

1 year ago

4.0.1-beta.1

2 years ago

4.0.1-alpha.24

2 years ago

4.0.1-alpha.23

2 years ago

4.0.1-alpha.20

2 years ago

4.0.1-alpha.21

2 years ago

4.0.1-alpha.22

2 years ago

3.2.4

2 years ago

4.0.1-alpha.13

2 years ago

4.0.1-alpha.14

2 years ago

4.0.1-alpha.11

2 years ago

4.0.1-alpha.12

2 years ago

4.0.1-alpha.17

2 years ago

4.0.1-alpha.18

2 years ago

4.0.1-alpha.15

2 years ago

4.0.1-alpha.16

2 years ago

4.0.1-alpha.19

2 years ago

3.2.4-beta.1

2 years ago

4.0.1-alpha.10

2 years ago

4.0.1-alpha.8

2 years ago

3.2.3

2 years ago

4.0.1-alpha.6

2 years ago

4.0.1-alpha.7

2 years ago

4.0.0-alpha.4

3 years ago

4.0.0-alpha.3

3 years ago

3.2.2

3 years ago

3.0.4

3 years ago

4.0.0-alpha.2

3 years ago

4.0.0-alpha.1

3 years ago

3.2.1

3 years ago

3.2.1-beta.2

3 years ago

3.2.0

3 years ago

3.2.1-beta.1

3 years ago

3.2.0-rc.3

3 years ago

3.2.0-rc.2

4 years ago

3.2.0-rc.1

4 years ago

3.2.0-beta.3

4 years ago

3.2.0-beta-2

4 years ago

3.2.0-beta.1

4 years ago

3.1.0-beta.13

4 years ago

3.1.0-beta.12

4 years ago

3.1.0-beta.11

4 years ago

3.1.0-alpha.10

4 years ago

3.1.0-alpha.9

4 years ago

3.1.0-alpha.8

4 years ago

3.1.0-alpha.7

4 years ago

3.1.0-alpha.6

4 years ago

3.1.0-alpha.5

4 years ago

3.1.0-alpha.4

4 years ago

3.1.0-alpha.1

4 years ago

3.1.0-alpha.3

4 years ago

3.0.3

4 years ago

3.0.3-rc.4

5 years ago

3.0.3-rc.3

5 years ago

3.0.3-rc.2

5 years ago

3.0.3-rc.1

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

3.0.0-rc.7

5 years ago

3.0.0-rc.6

5 years ago

3.0.0-rc.5

5 years ago

3.0.0-rc.4

5 years ago

3.0.0-rc.3

5 years ago

3.0.0-rc.2

5 years ago

3.0.0-rc.1

5 years ago

3.0.0-beta.1

6 years ago

3.0.0-alpha.8

6 years ago

3.0.0-alpha.7

6 years ago

3.0.0-alpha.6

6 years ago

3.0.0-alpha.5

7 years ago

3.0.0-alpha.4

7 years ago

3.0.0-alpha.3

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

3.0.0-alpha.2

7 years ago

2.0.2

7 years ago

3.0.0-alpha.1

7 years ago

2.0.1

8 years ago

2.0.0

8 years ago

2.0.0-rc.1

8 years ago

2.0.0-beta.11

8 years ago

2.0.0-beta.10

8 years ago

2.0.0-beta.9

8 years ago

2.0.0-beta.8

8 years ago

2.0.0-beta.7

8 years ago

2.0.0-beta.6

8 years ago

2.0.0-beta.5

8 years ago

2.0.0-beta.4

8 years ago

1.5.1

8 years ago

2.0.0-beta.3

9 years ago

1.5.0

9 years ago

1.5.0-rc.6

9 years ago

1.5.0-rc.5

9 years ago

1.5.0-rc.4

9 years ago

1.5.0-rc.3

9 years ago

1.5.0-rc.2

9 years ago

2.0.0-beta.2

9 years ago

2.0.0-beta.1

9 years ago

1.5.0-rc

9 years ago

1.4.3-rc

9 years ago

1.4.2

9 years ago

1.4.1

9 years ago

1.4.0

9 years ago

1.4.0-rc.1

9 years ago

1.4.0-beta.3

9 years ago

1.4.0-beta2

9 years ago

1.4.0-beta

9 years ago

1.3.6

9 years ago

1.3.6-rc.1

9 years ago

1.3.6-beta.3

9 years ago

1.3.6-beta.2

9 years ago

1.3.6-beta.1

9 years ago

1.3.5-beta.2

9 years ago

1.3.5-beta

9 years ago

1.3.4

9 years ago

1.3.4-beta2

9 years ago

1.3.4-beta

9 years ago

1.3.3

9 years ago

1.3.2

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.9.9

11 years ago