Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

How to create tables dynamically? #288

Open
zxg110 opened this issue Feb 26, 2019 · 1 comment
Open

How to create tables dynamically? #288

zxg110 opened this issue Feb 26, 2019 · 1 comment

Comments

@zxg110
Copy link

zxg110 commented Feb 26, 2019

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
Copy link
Collaborator

jdkoren commented Feb 26, 2019

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.

  • Each message belongs to a chat. This would be a foreign key to an ID in chats.
  • Each message has a sender. This would be a foreign key to a row to an ID in users.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants