tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
6.99k stars 1.43k forks source link

Tdlib custom database usage #460

Closed AaronPorts closed 5 years ago

AaronPorts commented 5 years ago

Can we use custom database (e.g. IndexedDB) to save user authorization data?

levlam commented 5 years ago

You can use setOption with options beginning with 'x' or 'X' to persistently store some small amount of data. Values of these options will be sent in updateOption on client launch along with values of all other options.

You can also use Chat.client_data field and setChatClientData method to store some per-chat data.

savely-krasovsky commented 5 years ago

@levlam but is there any plan to implement interface in TDLib for implementing custom data storages? For example iOS apps use CoreData, for server side usage it could be useful to use PostgreSQL, MySQL or even NoSQL-databases.

levlam commented 5 years ago

@l11R No, there is no such plans, It's easily possible to replace SQLite database with any other SQL database and internal key-value databases with any other key-value database in the С++-code, but this change is unlikely to give any significant performance improvement.

@AaronPorts It seems that I've misunderstood your question. There is no need for TDLib to know about existence of IndexedDB to store data there, when TDLib is used from a browser. Emscripten suppots out of the box IDBFS, a file-system which will store all data persistently in the IndexedDB. We will publish soon complete example of TDLib usage from web browser, which will include example of IDBFS usage for persistent data storage.

AaronPorts commented 5 years ago

@levlam Thanks for the answer. Looking forward to the example.

levlam commented 5 years ago

TDLib 1.4.0 includes an example of TDLib usage in a browser. You can also use NPM package tdweb if you don't want to build TDLib yourself.