Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Double quote MySQL JSON expressions #16308

Closed
wants to merge 2 commits into from
Closed

[5.3] Double quote MySQL JSON expressions #16308

wants to merge 2 commits into from

Conversation

themsaid
Copy link
Member

@themsaid themsaid commented Nov 8, 2016

Based on MySQL guide: http://dev.mysql.com/doc/refman/5.7/en/json-path-syntax.html

Names of keys must be double-quoted strings or valid ECMAScript identifiers

Some characters like Hyphens are not allowed in ECMAScript identifiers so we must double quote the parts of the JSON expression for it to work.

This change will convert meta->name->first-name to meta->'$."name"."first-name"'.

return $field.'->'.'"$.'.implode('.', $path).'"';
$path = collect($path)->map(function ($part) {
return '"'.$part.'"';
})->toArray();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can call implode on the collection:

$path = collect($path)->map(function ($part) {
    return '"'.$part.'"';
})->implode('.');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍

@taylorotwell
Copy link
Member

Ha, I just merged it and fixed the implode for you 😄

@themsaid themsaid deleted the doubleQuoteJSONPath branch November 8, 2016 14:41
@themsaid
Copy link
Member Author

themsaid commented Nov 8, 2016

😅 ok

@tillkruss tillkruss changed the title [5.3] Doubel quote MySQL JSON expressions [5.3] Double quote MySQL JSON expressions Nov 8, 2016
@sebestenyb
Copy link

Impressive!
Thank you gentlemen.

Cheers, Sebi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants