How should I store user settings in the database?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
19 views
In the web-project is planned quite a lot of settings for users. Also in the future they will have to add/remove.
Considered several options for storing the values of these settings:

1. Create two tables (assuming that the table with the user_id already exists):
1) option option_id;
2) the user_id, option_id, value.
2. Store all in one extra table: user_id, all_options_format(xml|json). In this case all settings are in a single line of xml or json format.
3. Again, an additional table but: key(user_id, option), value.

Which of these options is in your view preferable?
by | 19 views

5 Answers

0 like 0 dislike
Store in a separate place settings by default. For users to store in json/xml form, only differing from the default settings. Total user settings happens by applying different settings by default. Therefore, when adding new settings will change only one configuration in common, and however it will be available to the user. And when the user changes such settings, the changed value will be written in his personal configuration.
by
0 like 0 dislike
Mongo or Couch (and I'm sure many NoSQL) for storing data that is naturally represented as XML/JSON (tree of values with attributes) is ideal. To store and work with trees in SQL in General, not sugar, and when a rigid schema no...
by
0 like 0 dislike
If we talk about MySQL, PunBB, for example, as the quickest option to choose storage settings directly in the users table: each time you configure your column.
If you often change the list of settings, it is easier to bring them to a separate table where the key is a user_id, and the columns themselves will settings.
Then you can use one query to get the data immediately ready to save here much sense no, but you can do complex queries in case.
But in General certainly it is better to use NoSQL for this.
by
0 like 0 dislike
If stored as field=value, then there is a flaw in the handling of nested properties. For example, the application has a window, and each window can be applied your style. Naturally, all that belongs to this window, is a "tree view". In this case, a convenient XML. The disadvantage of this method I think is clear — you have to upload the whole field, and then to handle it. But the advantage is all pretty grouped together, it is not difficult to handle and not difficult to display in a report
by
0 like 0 dislike
You put the wrong question. how to store — no difference, the data will not deteriorate. The question is what are you going to do with them. And here are the options:
\r
If you want to make sample users by properties like group membership, such properties should be explicitly. To normalize or not — decide for yourself.
\r
If options are used together, for example when you render the page for him and most of all, it makes sense to package the array into json/xml.
\r
I personally like the version of Wordpress where there is a separate table for named options ( user, post, or whatever ) and to be stored in either a single value or an array in separate lines, but with the same name, on which you can make a sample or a serialized array as desired. Precisely how convenient is to use them. And, if desired, all options can be mixed.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
27,959 users