Home > database >  Storing many key-values pair correctly?
Storing many key-values pair correctly?

Time:06-25

I have some settings files, that will differ in naming of the different settings.

setting1 : true
setting2 : false
setting3 : false

settingsss1 : true
settingsss2 : true
settingsss3 : true

the naming is user generated so cant really make columns for them.

i though doing something like making a table with

Id - Key - Value

This would then give 50 entries for a settings file with 50 settings. Would it be better to just save these as JSON string in a field in the DB as MediumText?

i expect to have around 100 new saves of these every day. giving 100 x 50 x 365 = 1.800.000 entries a year..

The thing is I need to be able to look thru these in a decent way, to compare their settings.

should I go with JSON string or entry pr. parameter. or even a 3rd option?

CodePudding user response:

For simple, flat key/value pairs with simple values, use a normal table. If the values are just true/false use boolean for the value column to save a little space.

If the values can be a mix of types (dates, numbers, strings, lists, nested key/value pairs) use the JSON type. It can be indexed and searched.

Millions of entries a year is not a lot if they are properly indexed. Handling large amounts of data is what SQL databases are good at.

  • Related