1.0.22 • Published 9 months ago
@ea-utilities/db-sync v1.0.22
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-syncUsage (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.22
9 months ago
1.0.21
1 year ago
1.0.20
1 year ago
1.0.19
1 year ago
1.0.18
1 year ago
1.0.17
1 year ago
1.0.16
1 year ago
1.0.15
1 year ago
1.0.14
1 year ago
1.0.13
1 year ago
1.0.12
1 year ago
1.0.11
1 year ago
1.0.10
1 year ago
1.0.9
1 year ago
1.0.8
1 year ago
1.0.7
1 year ago
1.0.6
1 year ago
1.0.5
1 year ago
1.0.4
1 year ago
1.0.3
1 year ago
1.0.2
1 year ago
1.0.1
1 year ago
1.0.0
1 year ago