yahoo / squidb

SquiDB is a SQLite database library for Android and iOS
https://github.com/yahoo/squidb/wiki
Apache License 2.0
1.31k stars 132 forks source link

How to create tables dynamically? #288

Open zxg110 opened 5 years ago

zxg110 commented 5 years ago

I have such a need.I want to create a chat information table for each friend when I receive a chat message from the Internet.For example when I receive chat message from my friend Tom,I will check if there are tom_chat_table locally.If it exists,I will insert this chat message to tom_chat_table.If it not exists,I will create tom_chat_table and insert this chat message to tom_chat_table. Thanks

jdkoren commented 5 years ago

SquidDatabase has methods tryCreateTable() (or tryExecSql() if you have arbitrary SQL you want to run), but this is not a good way to approach this problem. Regardless which kind of database or you use, your approach is going to run into problems because you are not identifying and associating your entities correctly.

The entities you have are chats, messages, and users. Preferably, these entities would also exist on your server and have globally unique IDs.