NAME

DBIO::SQLite::JSON::Op - SQLite JSON path-extraction operator object built by json()

VERSION

version 0.900007

DESCRIPTION

Operator object representing a JSON path extraction against a SQLite column. You do not construct this class directly — use the json() helper from DBIO::SQLite::JSON:

use DBIO::SQLite::JSON qw(json);

my $expr = json('me.data')->get_text('$.status');  # DBIO::SQLite::JSON::Op
$rs->search( $expr->eq('active') );                 # WHERE (me.data ->> ?) = ?

The object is built in two stages, mirroring DBIO::PostgreSQL::Vector::Op:

  • json($col) returns a column-only operator.

  • A selector method — "extract", "get" or "get_text" — chooses the extraction form and the path, and returns a fresh operator carrying the rendered SQL and its bind. The path always travels as a placeholder bind, never inlined.

  • A consumption method — a comparison ("eq" …), "is_null", "as_order" or "as_select" — turns that into an SQL::Abstract literal-with-bind fragment.

"extract" emits the json_extract function (JSON1, SQLite 3.9+); "get" and "get_text" emit the -> and ->> operators, which need SQLite 3.38+.

METHODS

extract

json('me.data')->extract('$.status')
# json_extract(me.data, ?)     bind: '$.status'

The portable json_extract() function form. The path is bound. Available wherever the JSON1 extension is (SQLite 3.9+, compiled in by default).

get

json('me.data')->get('$.status')
# me.data -> ?                 bind: '$.status'

The -> operator (SQLite 3.38+), which yields a JSON value. Use for extracting a sub-document; for comparing a scalar value use "get_text".

get_text

json('me.data')->get_text('$.status')
# me.data ->> ?                bind: '$.status'

The ->> operator (SQLite 3.38+), which yields a text / SQL value. This is the natural form for scalar comparisons.

eq

json('me.data')->get_text('$.status')->eq('active')
# WHERE (me.data ->> ?) = ?    bind: '$.status', 'active'

ne

json('me.data')->get_text('$.status')->ne('deleted')
# WHERE (me.data ->> ?) != ?

lt

json('me.stats')->get_text('$.score')->lt(50)
# WHERE (me.stats ->> ?) < ?

le

json('me.stats')->get_text('$.score')->le(100)
# WHERE (me.stats ->> ?) <= ?

gt

json('me.stats')->get_text('$.score')->gt(100)
# WHERE (me.stats ->> ?) > ?

ge

json('me.stats')->get_text('$.score')->ge(100)
# WHERE (me.stats ->> ?) >= ?

like

json('me.data')->get_text('$.name')->like('John%')
# WHERE (me.data ->> ?) LIKE ?

is_null

json('me.data')->get_text('$.avatar')->is_null
# WHERE (me.data ->> ?) IS NULL

is_not_null

json('me.data')->get_text('$.email')->is_not_null
# WHERE (me.data ->> ?) IS NOT NULL

as_order

$rs->search( {}, { order_by => json('me.data')->get_text('$.total')->as_order } )
# ORDER BY me.data ->> ?

Returns a literal-with-bind fragment for an order_by value; the path travels as a bind. Combine with -asc/-desc as usual:

{ order_by => { -desc => json('me.data')->get_text('$.total')->as_order } }
# ORDER BY me.data ->> ? DESC

as_select

$rs->search( {}, { select => [ json('me.data')->extract('$.status')->as_select('status') ] } )
# SELECT json_extract(me.data, ?) AS status

Returns a literal-with-bind fragment selecting the extracted value under $alias. $alias is emitted verbatim — pass an identifier, not user input.

SEE ALSO

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.