Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update (see previous version below):</strong></p> <p>With both your solution and my previous version there is actually the problem that not all information from your array structure is saved. You can still avoid <code>api.scopes.1</code> by putting the last element of the option name in a separate field. If you combine this with soft deletion, you can use <code>INSERT ... ON DUBLICATE UPDATE</code>.</p> <pre><code>+----------+-------------------+---------------+------------------+---------+ | user_id* | config_group* | config* | value | deleted | +----------+-------------------+---------------+------------------+---------+ | 1 | user | is_developer | 1 | 0 | | 1 | user | api_access | 1 | 0 | | 1 | api.scopes | 1 | astro | 0 | | 1 | api.scopes | 2 | user_info | 0 | | 1 | api | default_scope | user_info | 0 | | 1 | astro | location_id | 12345 | 0 | | 1 | astro | timezone | America/New_York | 0 | | 1 | astro.coordinates | latitude | 12.22 | 0 | | 1 | astro.coordinates | longitude | 24.44 | 0 | +----------+-----------------------------------+------------------+---------+ * marks key columns </code></pre> <p><strong>Previous version:</strong></p> <p>If you split your data in two tables you can use a unique key for each of them.</p> <p>The first table contains all config options which take on a single value (* marks key columns):</p> <pre><code>+----------+-----------------------------+------------------+ | user_id* | config* | value | +----------+-----------------------------+------------------+ | 1 | user.is_developer | 1 | | 1 | user.api_access | 1 | | 1 | api.default_scope | user_info | | 1 | astro.location_id | 12345 | | 1 | astro.timezone | America/New_York | | 1 | astro.coordinates.latitude | 12.22 | | 1 | astro.coordinates.longitude | 24.44 | +----------+-----------------------------+------------------+ </code></pre> <p>The second table contains all options which consist of a set of values (with no dublicates; * marks key columns):</p> <pre><code>+----------+-----------------------------+------------------+ | user_id* | config* | value* | +----------+-----------------------------+------------------+ | 1 | api.scopes | astro | | 1 | api.scopes | user_info | +----------+-----------------------------+------------------+ </code></pre> <p>Thus you can use your database to ensure data integrity. <code>INSERT ... ON DUBLICATE UPDATE</code> works naturally with the first table. You can also use it with your second table if you are willing to use soft delete:</p> <pre><code>+----------+-----------------------------+------------------+---------+ | user_id* | config* | value* | deleted | +----------+-----------------------------+------------------+---------+ | 1 | api.scopes | astro | 0 | | 1 | api.scopes | user_info | 0 | | 1 | api.scopes | old | 1 | +----------+-----------------------------+------------------+---------+ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload