KMP PHP API Reference

JsonFieldBehavior extends Behavior
in package

JsonField Behavior

Enables querying JSON fields using database-specific JSON extraction syntax. Provides addJsonWhere() for $.path-based JSON field filtering.

Tags
see

/docs/3.2-model-behaviors.md#jsonfield-behavior

Table of Contents

Methods

addJsonWhere()  : SelectQuery
Add JSON path WHERE condition to a query.
buildJsonExtractExpression()  : mixed
Build driver-specific JSON extraction expression.
extractJsonPathSegments()  : array<string|int, string>
Convert a JSON path ($.a.b) to path segments.
getDriverName()  : string
Resolve current database driver short name.
quoteIdentifierPath()  : string
Quote a possibly qualified identifier path.

Methods

addJsonWhere()

Add JSON path WHERE condition to a query.

public addJsonWhere(SelectQuery $query, string $field, string $path, mixed $value) : SelectQuery
Parameters
$query : SelectQuery

The query to modify

$field : string

The JSON field name in the table

$path : string

JSON path using $.notation (e.g., '$.preferences.email')

$value : mixed

Value to compare against

Return values
SelectQuery

Modified query with JSON WHERE condition

buildJsonExtractExpression()

Build driver-specific JSON extraction expression.

protected buildJsonExtractExpression(SelectQuery $query, string $field, string $path) : mixed
Parameters
$query : SelectQuery

Query being modified

$field : string

Field name (optionally table-qualified)

$path : string

JSON path using $.notation

Return values
mixed

SQL expression compatible with QueryExpression::eq()

extractJsonPathSegments()

Convert a JSON path ($.a.b) to path segments.

protected extractJsonPathSegments(string $path) : array<string|int, string>
Parameters
$path : string

JSON path

Return values
array<string|int, string>

Path segments

getDriverName()

Resolve current database driver short name.

protected getDriverName(SelectQuery $query) : string
Parameters
$query : SelectQuery

Query being modified

Return values
string

Driver short class name (e.g., Mysql, Postgres, Sqlite)

quoteIdentifierPath()

Quote a possibly qualified identifier path.

protected quoteIdentifierPath(SelectQuery $query, string $identifier) : string
Parameters
$query : SelectQuery

Query being modified

$identifier : string

Identifier path (table.column)

Return values
string

Quoted identifier path


        
On this page

Search results