1.0.22 • Published 1 year 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
1 year ago
1.0.21
1 year ago
1.0.20
1 year ago
1.0.19
2 years ago
1.0.18
2 years ago
1.0.17
2 years ago
1.0.16
2 years ago
1.0.15
2 years ago
1.0.14
2 years ago
1.0.13
2 years ago
1.0.12
2 years ago
1.0.11
2 years ago
1.0.10
2 years ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago