0

I am trying to create a chat project and I need to create message-tables dynamically.

Lets say there are 3 users, user1, user2 and user3. When user1 sends the first time a message to user2 I want a table(user1_user2) to be created. When user1 sends to user3 I want a table with name (user1_user3) to be created and so on.

How do I create dynamically tables and models so I can access the data? I am using sqlite3 as DB. A solution I have thought is to use a NoSQL DB like mongoDB to create the messages-tables and sqlite3 for the other tables I already have, but it does not sound correct to me.

Have you any idea what I can do?

Ivane Gkomarteli
  • 133
  • 3
  • 18
  • Why don't you simply use a single table "messages(from,to,text)"? – CL. Mar 08 '17 at 10:39
  • 1
    Hmm I was thinking to create one table like you said but what if there are a lot of users with a lot of messages? Also, I am thinking that if I have different tables for every two users I will be able to use triggers to update messages in the front end. – Ivane Gkomarteli Mar 08 '17 at 11:10
  • @IvaneGomarteli, with you approach, if the number of users increase significantly, number of tables will also increase. Bette to use CL's approach – Pramod Mar 08 '17 at 11:23
  • When you have lots of rows, queries are still efficient if you have appropriate indexes. – CL. Mar 08 '17 at 15:11

0 Answers0