1.0.21 • Published 9 months ago

@ea-utilities/db-sync v1.0.21

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

db-sync

Add a local database using IndexedDb, user can syncronize changes telegram (Or create new implementation following ISyncClient interface)

Dependencies

  • GramJs when telegram chat is used as db

Installation

Run in your terminal

npm i @ea-utilities/db-sync

Usage (LocalDb)

export interface UserModel {
    id: string;
    name: string;
    lastName: string;
    birthday: Date;
}

DB

const indexedDb = new IndexedDbClient("localDb", ["users", ...]);
indexedDb.syncAll();

Collections

const usersCollection: DbInstace<UserModel> = new DbInstace(indexedDb, "users");
const filesCollection = new DbFileInstance(indexedDb);

Get data

const users = await usersCollection.get();

Save or update

usersCollection.addOrUpdate([...UserModel]);
usersCollection.add([...UserModel]);
usersCollection.update([...UserModel]);

Delete

usersCollection.delete(UserModel.id);

Listen for changes

usersCollection.subscribe(() => {
    users = await usersCollection.get();
});

Usage (Telegram sync)

const telegramInstance = new TelegramSyncClient(isConnected => {
    if (isConnected) {
        indexedDb?.syncAll();
    }
});

telegramInstance.auth({
    chatName: string;
    appId: number;
    appHash: string;
    session?: string;
    phone: string;
});

const indexedDb = new IndexedDbClient("localDb", ["users", ...], telegramInstance);
indexedDb?.syncAll();
1.0.21

9 months ago

1.0.20

9 months ago

1.0.19

10 months ago

1.0.18

10 months ago

1.0.17

10 months ago

1.0.16

10 months ago

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago