2.4.2 • Published 7 months ago

@hollax/dexie-orm v2.4.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 months ago

Test

Introduction

Simple ORM model for dexiejs (A Minimalistic Wrapper for IndexedDB)

Installation

  npm i @hollax/dexie-orm dexie

Quick Reference

const {Model, setup} = require('@hollax/dexie-orm');

class Post extend Model{

    title?: string
    status?:string
    body?: string
    
    static tableName = 'posts';

    static getSchema(){
        return [
            {
                version: 1,
                columns: "id++, **tags"
            }
        ];
    }

}

NOTE: Don’t declare all columns like in SQL. You only declare properties you want to index, that is properties you want to use in a where(…) query.

Somewhere in the app:

    const Dexie = require('dexie');

    let db = new Dexie("MyDatabase");
    setup(db, [Post,User]);

Insert new record

    let post = new Post({
        title: 'Hello World!'
    });

    post.save()
    .then(()=>{
        console.log('Post saved ', post.id);
    });

Get single record

    let post = await Post.find(1)
    console.log('Post 1', post);
    let post2 = await Post.find(2)
    console.log('Post 2', post2);

Using first method

    let post = await Post.first({
        title: 'Hello World!'
    });
    console.log('Result of Post.first', post.title);
    console.log('Post id 1 title ', post.title);

Get multiple records

    let posts = await Post.all();
    console.log('All posts', posts);

Update record

    let post = await Post.find(1);
    post.title = "Simple Post";
    await post.save()

Delete record

    let post = await Post.find(1);
    await post.delete()

    console.log('find result after deleting record', await Post.find(1))

Testing

The library uses fake-indexeddb and jest for Testing.

Running the test:

 npm test
2.4.2

7 months ago

2.4.1

9 months ago

2.4.0

9 months ago

2.3.0

9 months ago

2.2.2

9 months ago

2.2.1

9 months ago

2.2.0

9 months ago

2.1.1

9 months ago

2.1.0

9 months ago

2.0.2

9 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.0.0

9 months ago