A
A
Alexander Razumov2016-05-07 17:41:25
PHP
Alexander Razumov, 2016-05-07 17:41:25

How to create a database schema for a chat and on what?

The bottom line is this: you need to make a chat in which you can also exchange files. Screenshot example. I understand how to do it without files (using sql). But how to make it so that with one request you can immediately select, for example, 100 recent messages between two users, and if there are files in a message, then they also need to be displayed?
If you store files for one message as a string, then I think it will not be a normalized form? Although at first glance, this solution seems to be the simplest. But in this case, it is not clear how to extract its path on the server with one request for each file?
I have no idea how to combine 3 entities: users, text messages, files into one selection, one request.
Maybe in this task it is better to use nosql solutions? The data will be stored close to the model.
If anyone has encountered a similar problem, I will be glad to hear advice, links, suggestions.
Thank you.
Screen:
680e3b197ec14f75ba8e7d39fde69c8d.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
coderisimo, 2016-05-08
@razumovsu

Maybe I did not understand the essence of the question, but what is the problem?
If one message -1 file , then just add a field where the link to it (to the file) is stored. If there can be many of them (files attached to the message), then the field contains the path to the directory from which you need to insert links to all the files in the chat text. The directory name can be generated randomly or using the entry ID (as long as it is unique).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question