NAME

DBIO::PostgreSQL::JSONB::Op - JSONB path-extraction operator object built by jsonb()

VERSION

version 0.900007

DESCRIPTION

Operator object representing a text-extraction path into a PostgreSQL JSONB column. You do not construct this class directly — use the jsonb() helper from DBIO::PostgreSQL::JSONB:

use DBIO::PostgreSQL::JSONB qw(jsonb);

my $expr = jsonb('me.data', 'status');   # DBIO::PostgreSQL::JSONB::Op
$rs->search( $expr->eq('active') );      # WHERE (me.data->>'status') = ?

Each comparison method returns a SQL::Abstract literal-with-bind fragment suitable for passing to search().

METHODS

new

my $expr = DBIO::PostgreSQL::JSONB::Op->new( col => 'me.data', path => ['status'] );

The constructor jsonb() calls. col is the column as it is written into the SQL, path an ArrayRef of the path elements. The identifiers of this DSL are code: col is letters, digits, underscores and dots (me.data), and any other form throws a DBIO::Exception. The path elements are data: each travels as a bind. A path without an element croaks when a method renders the expression.

eq

jsonb('me.data', 'status')->eq('active')
# WHERE (me.data->>?) = ?

ne

jsonb('me.data', 'status')->ne('deleted')
# WHERE (me.data->>?) != ?

lt

jsonb('me.stats', 'score')->lt(50)
# WHERE (me.stats->>?) < ?

le

jsonb('me.stats', 'score')->le(100)
# WHERE (me.stats->>?) <= ?

gt

jsonb('me.stats', 'score')->gt(100)
# WHERE (me.stats->>?) > ?

ge

jsonb('me.stats', 'score')->ge(100)
# WHERE (me.stats->>?) >= ?

like

jsonb('me.data', 'name')->like('John%')
# WHERE (me.data->>?) LIKE ?

ilike

jsonb('me.data', 'name')->ilike('%smith%')
# WHERE (me.data->>?) ILIKE ?

is_null

jsonb('me.data', 'avatar')->is_null
# WHERE (me.data->>?) IS NULL

Returns a condition fragment that checks whether the path resolves to SQL NULL (i.e. the key is absent or the value is JSON null).

is_not_null

jsonb('me.data', 'email')->is_not_null
# WHERE (me.data->>?) IS NOT NULL

as_order

$rs->search( {}, { order_by => jsonb('me.score', 'total')->as_order } )
# ORDER BY (me.score->>?)    bind: total

Returns a literal-with-bind fragment suitable for use as an order_by value. Combine with -asc/-desc wrappers as usual:

{ order_by => { -desc => jsonb('me.score', 'total')->as_order } }
# ORDER BY (me.score->>?) DESC

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.