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.6] Add whereJsonContains() to SQL Server #24448

Merged
merged 1 commit into from
Jun 5, 2018
Merged

[5.6] Add whereJsonContains() to SQL Server #24448

merged 1 commit into from
Jun 5, 2018

Conversation

staudenmeir
Copy link
Contributor

@staudenmeir staudenmeir commented Jun 4, 2018

Adds Builder::whereJsonContains() (#24330) to SQL Server 2016+ using OPENJSON().

While MySQL and PostgreSQL expect the binding as a JSON string, SQL Server requires the raw value.
This is why we need a separate prepareBindingForJsonContains() method.

compileJsonContains() has to differentiate between columns without and with a path (column->path).
In the first case, we have to wrap the column in OPENJSON(). In the second case, we have to replace JSON_VALUE() (coming from wrapJsonSelector()) with OPENJSON(). I also added tests for path-less columns to MySQL and Postgres.

There are three limitations:

  • NULL values don't work.
  • Boolean values only work as strings. The downside is that this also finds "true"/"false" strings.
  • Arrays don't work: ->whereJsonContains('options->languages', ['de', 'en'])
    In MySQL and PostgreSQL this can be used as the short version of ->whereJsonContains('options->languages', 'de')->whereJsonContains('options->languages', 'en').

@taylorotwell taylorotwell merged commit 8038c3d into laravel:5.6 Jun 5, 2018
@staudenmeir staudenmeir deleted the json-contains-sql-server branch June 5, 2018 13:16
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.

2 participants