Sign in to follow this  
Division

JSON string vs multiple rows in MYSQL

Recommended Posts

I am working on a phone system.

I've decided to save phone contacts as JSON string in the phone table, cuz its no heavy overload.

When it comes to messages between players, I am not quite sure if I should store huge JSON strings.

What would you do? Something like JSON:

messages: [
{
	sender: 01234567
    messages: [
    {
    	timestamp: x,
        message: 'xyzxyzxyzxyz'
     },
     {
     	timestamp: x2,
        message: 'xyz2xyz2xyz2',
     }, .....]
},
{
	sender: 76543210,
    messages: ....
}
   

or would you store multiple rows in database like:

phone_messages:

- ID (PK, AI): int
- sender_phone (FK): int
- receiver_phone (FK): int
- timestamp: DateTime
- message: string

 

With multiple rows its quite easier to maintain when it comes to filter and max limit while a JSON always needs to be deserialized, serialized, ...

 

Share this post


Link to post
Share on other sites
Posted (edited)

Why you would store JSON Strings to a database when MySQL is made for massive data flows? Even it it makes no difference for you, because your database will never be that huge like a big online portal.. But tell me why you would store them in plain?

 

Just create different tables at mysql.. eg. "phone_messages", "phone_whatever".. and use your queries or orm's to receive them. After this you create a JSON string at the server side and send it over to the client.

 

And if you open your messages.. make sure you load up just 5 and if you scroll up or down in your phone.. you load up the next ones.

Edited by DevGrab
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.