unframed / JSONModel.php

"People love ORMs"
GNU Lesser General Public License v3.0
28 stars 1 forks source link

The JSON column revisited #5

Closed samlevin closed 9 years ago

samlevin commented 9 years ago

how or why do the contents of the JSON column eventually become "consistent"? I'm still very new to the idea, and am interested in using the JSON column, but it eludes me!

laurentszyster commented 9 years ago

The JSON column becomes consistent for a relation when a REPLACE occurs.

The JSON column becomes inconsistent when an UPDATE occurs.

However, this only matters when using the json method. Because only then is the JSON column content returned as is. When using select on a model with a JSON column, the content of that JSON column will be updated with the content of the other columns selected, ie: made consistent.

So, to recap about consistency:

  1. update makes the JSON column inconsistent;
  2. replace (and insert) makes the JSON column consistent;
  3. select (and relate) returns consistent data for the selected columns;
  4. json returns eventually consistent data as fast as possible.
laurentszyster commented 9 years ago

Before using it, remember that this JSON column serves only two purposes:

  1. Handle the mapping of non-scalar JSON values in an SQL table.
  2. Load JSON objects that are eventually consistent with SQL relations.

If your application requires only scalars values and does not need a big speedup in the dynamic selection of eventually consistent data from an SQL database, don't use the JSON column.

Use it only if you must store non-scalars values in an SQL database or if your application would benefit from a cache of eventually consistent JSON objects.