Ensure querying JSON nested values when parent keys are unknown is possible in all supported databases

Created on 5 June 2024, 11 months ago

Problem/Motivation

Follow up to ๐Ÿ“Œ Prevent modules from being uninstalled if they provide field types used in an Experience Builder field Fixed

In that issue we needed match the field expression in test data like this

$this->createNode([
      'title' => 'Test node',
      'type' => 'article',
      'field_xb_test' => [
        'tree' => '[{"uuid":"dynamic-static-card2df","type":"sdc_test:my-cta"}]',
        // cspell:ignore centity dtitle elink furi fvalue
        'props' => '{"dynamic-static-card2df":{"text":{"sourceType":"dynamic","expression":"\u2139\ufe0e\u241centity:node:article\u241dtitle\u241e\u241fvalue"},"href":{"sourceType":"static:field_item:link","value":{"uri":"https:\/\/drupal.org","title":null,"options":[]},"expression":"โ„น๏ธŽlinkโŸuri"}}}',
      ],
    ]);

Under props we need to match expression with the field expression โ„น๏ธŽlinkโŸuri and we don't know the parent keys are going to be.

In MariaDB and MySQL this was pretty easy
$select->where("JSON_EXTRACT($column_name, '$.*.*.expression') LIKE '%$field_expression%'");

Or
$select->where("JSON_SEARCH($column_name, 'all', '%$field_expression%') LIKE '%$.%.%.expression%'");

Both work. `JSON_EXTRACT` is supported in Sqlite but it does not find a match. JSON_SEARCH is not supported in Sqlite

Haven't researched MariaDB yet.

Steps to reproduce

Proposed resolution

Probably there are ways to do this in all supported DB's but likely the solution will be different.

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ“Œ Task
Status

Active

Component

Data model

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024