1.1.1 • Published 22 days ago

@pvermeer/dexie-rxjs-addon v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
22 days ago

Dexie RxJs Addon

NPM Version Build Status semantic-release Conventional Commits

Install over npm

npm install @pvermeer/dexie-rxjs-addon rxjs

Dependencies

rxjs: https://rxjs-dev.firebaseapp.com/

Extend RxJs to your Dexie Database!

Plugin is written to extend Dexie.js with your own RxJs by adding some methods / properties to the Dexie classes. RxJs is not bundled so you can use your own implementation.

Example (ES6)

import Dexie from 'dexie';
import { dexieRxjs } from '@pvermeer/dexie-rxjs-addon';

// Declare Database
const db = new Dexie("FriendDatabase", {
    addons: [dexieRxjs]
});
db.version(1).stores({ friends: "++id, name, shoeSize, age" });

// Open the database
db.open()
    .then(() => {
        console.log('DB loaded! :D')
        // Use Dexie
    });

Example (Typescript)

import Dexie from 'dexie';
import { dexieRxjs } from '@pvermeer/dexie-rxjs-addon';

interface Friend {
    id?: number;
    name?: string;
    shoeSize?: number;
    age?: number;
}

// Declare Database
class FriendsDatabase extends Dexie {
    public friends: Dexie.Table<Friend, string>;
    constructor(name: string) {
        super(name);
        dexieRxjs(this);
        this.version(1).stores({
            friends: '++id, name, shoeSize, age'
        });
    }
}

const db = new FriendDatabase('FriendsDatabase');

// Open the database
db.open()
    .then(() => {
        console.log('DB loaded! :D')
        // Use Dexie
    });

Example (HTML import)

Bundled & minified package: https://unpkg.com/@pvermeer/dexie-rxjs-addon@latest/dist/dexie-rxjs-addon.min.js.

Addon is export as namespace DexieRxjsAddon

<!doctype html>
<html>
    <head>
        <!-- Include Dexie -->
        <script src="https://unpkg.com/dexie@latest/dist/dexie.js"></script>

        <!-- Include RxJs -->
        <script src="https://unpkg.com/rxjs/bundles/rxjs.umd.min.js"></script>

        <!-- Include DexieRxjsAddon (always after dependencies) -->
        <script src="https://unpkg.com/@pvermeer/dexie-rxjs-addon@latest/dist/dexie-rxjs-addon.min.js"></script>

        <script>

            // Define your database
            const db = new Dexie("FriendDatabase", {
                addons: [DexieRxjsAddon.dexieRxjs]
            });
            db.version(1).stores({ friends: "++id, name, shoeSize, age" });

            // Open the database
            db.open()
                .then(() => {
                    console.log('DB loaded! :D')
                    // Do Dexie stuff
                });
        </script>
    </head>
</html>

API

The packet exposes new methods and properties on Dexie classes:

(Will be expanded on)

    interface Dexie {
        /**
         * Get on('changes') from 'dexie-observable' as an RxJs observable and observe changes.
         * @link https://dexie.org/docs/Observable/Dexie.Observable
         */
        changes$: Observable<IDatabaseChange[]>;
    }

    interface Table<T, Key> {
        /**
         * Get a single record as an RxJs observable and observe changes.
         * Uses Table.get().
         * @param key Primary key to find.
         */
        get$(key: Key): Observable<T | undefined>;
        /**
         * Get a full table as an RxJs observable and observe changes.
         * Uses Table.toArray().
         */
        $: Observable<T[]>;
    }

    interface Collection<T, Key> {
        /**
         * Get a collection (Table.where()) as an RxJs observable and observe changes.
         * Uses Collection.toArray().
         */
        $: Observable<T[]>;
    }

Dexie.js

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

1.1.2-beta.0

23 days ago

2.0.0-beta.0

22 days ago

1.1.1

12 months ago

1.1.1-beta.0

1 year ago

1.1.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.1.0-beta.2

1 year ago

1.1.0-beta.1

1 year ago

1.1.0-beta.0

1 year ago

1.0.3-beta.0

2 years ago

1.0.3-beta.2

2 years ago

1.0.3-beta.1

2 years ago

1.0.3-beta.4

1 year ago

1.0.3-beta.3

2 years ago

1.0.3-beta.5

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0-beta.36

2 years ago

1.0.0-beta.22

2 years ago

1.0.0-beta.23

2 years ago

1.0.0-beta.20

2 years ago

1.0.0-beta.21

2 years ago

1.0.0-beta.28

2 years ago

1.0.0-beta.29

2 years ago

1.0.0-beta.26

2 years ago

1.0.0-beta.27

2 years ago

1.0.0-beta.24

2 years ago

1.0.0-beta.25

2 years ago

1.0.0-beta.33

2 years ago

1.0.0-beta.34

2 years ago

1.0.0-beta.31

2 years ago

1.0.0-beta.32

2 years ago

1.0.0-beta.30

2 years ago

1.0.0-beta.35

2 years ago

1.0.0-beta.19

2 years ago

1.0.0-beta.17

3 years ago

1.0.0-beta.18

3 years ago

1.0.0-beta.16

4 years ago

1.0.0-beta.15

4 years ago

1.0.0-beta.14

4 years ago

1.0.0-beta.13

4 years ago

1.0.0-beta.12

4 years ago

1.0.0-beta.11

4 years ago

1.0.0-beta.10

4 years ago

1.0.0-beta.9

4 years ago

1.0.0-beta.7

4 years ago

1.0.0-beta.8

4 years ago

1.0.0-beta.6

4 years ago

1.0.0-beta.5

4 years ago

1.0.0-beta.4

4 years ago

1.0.0-beta.3

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.1

4 years ago