The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Tangram::Expr - manipulate expressions on database server side

SYNOPSIS

        $expr = $remote->{$field}
   
        $expr1 op $expr2
   
        $expr->includes( $obj )
        $expr->includes( $remote )

DESCRIPTION

Tangram::Expr objects represent expressions that will be evaluated on the database server side.

Expr objects fall into the following hierarchy:

      Expr
      |
      +--ScalarExpr
      |  |
      |  +--NumericExpr
      |  |
      |  +--StringExpr
      |  |
      |  +--RefExpr
      |
      +--CollExpr
      |
      +--Filter

ScalarExpr

ScalarExpr objects represent single values, similar to ordinary Perl scalars. They are further classified into numeric, string and reference subtypes.

NumericExpr

NumericExpr objects can be compared using the usual operators ==, !=, <, >, <= and >=. The other operand must be either another NumericExpr, or a normal Perl numeric value. The result of the comparison is a Filter.

StringExpr

StringExpr objects can be compared using the usual operators eq, ne, lt, gt, le, and ge. The other operand must be either a StringExpr or any Perl scalar value. Tangram will automatically quote the operand as required by the SQL syntax. The result of the comparison is a Tangram::Filter.

RefExpr

RefExpr objects can be compared for equality using the usual operators == and !=. The other operand must be another RefExpr, a persistent object or undef(). The result of the comparison is a Filter.

CollExpr

A CollExpr objects represents a collection inside an object. It supports the includes methods, which returns a Tangram::Filter stating that the collection must contain the operand. The operand may be a Tangram::Remote, a persistent object, or an object ID.

operator < is provided as a synonym for includes().

Filter

Filter objects represent logical expressions, or conditions. Filters support logical operators &, | and !. Note that a single ampersand or vertical bar must be used. The result is a Filter.

EXAMPLES

$person is called 'Homer'

        $person->{name} eq 'Homer'

$person is older than 35

        $person->{age} > 35

$person is married to $homer

        $person->{partner} == $homer

$person is not $homer

        $person != $homer

$person is not $homer and is older than 65

        $person != $homer & $person->{age} > 65

$person is $bart's parent

        $person->{children}->includes( $bart )
        $person->{children} < $bart

$person is not $bart's parent

        !$person->{children}->includes( $bart )
        !($person->{children} < $bart)

SEE ALSO

Tangram, Tangram::Remote, Tangram::Expr, Tangram::Storage, overload