3
Tangram::Expr - manipulate expressions on database server side
7
my ($r1, $r2) = $storage->remote(qw( ... ));
9
$r1->{field} operator $value
10
$r1->{field} operator $r2->{field2}
12
$r1->{collection}->includes( $obj )
13
$r1->{collection}->exists( $obj, $filter )
17
Tangram::Expr objects represent expressions that will be evaluated on
18
the database server side.
20
Expression objects fall into one of the following categories: numeric,
21
string, reference or collection.
23
The methods in Expr are needed only by people extending Tangram. See
26
=head1 NUMERIC EXPRESSIONS
28
Numeric expression objects can be compared using the operators ==, !=,
29
<, >, <= and >=. The other operand must be either another numeric
30
expression object, or a normal Perl numeric value. The result of the
31
comparison is a Filter.
33
=head1 STRING EXPRESSIONS
35
String expression objects can be compared using the operators eq, ne,
36
lt, gt, le, and ge. The other operand must be either a string
37
expression object or any Perl scalar value. Tangram will automatically
38
quote the operand as required by the SQL syntax. The result of the
39
comparison is a Tangram::Filter.
41
String expression objects also support the method like($str), where
42
$str is a string that may contain SQL wildcards. The result is a
43
Tangram::Filter that translates to a SQL C<LIKE $str> predicate.
45
=head1 REFERENCE EXPRESSIONS
47
Reference expression objects can be compared for equality using
48
operators == and !=. The other operand must be another reference
49
expression, a persistent object or undef(). The result of the
50
comparison is a Filter.
52
=head1 COLLECTION EXPRESSIONS
54
Collection expression objects represents a collection inside an
55
object. It supports the includes() and exists() methods, which returns
56
a Tangram::Filter stating that the collection must contain the
57
operand. exists() uses a subselect.
59
The operand may be a Tangram::Remote, a persistent object,
62
operator < is provided as a synonym for includes().
66
Predicate objects represent logical expressions, or
67
conditions. Predicates support logical operators &, | and !. Note that
68
a I<single> ampersand or vertical bar must be used. The result is
73
=head2 new($type, $expr, @remotes)
75
Returns a new instance.
77
$type is a Type object corresponding to this expression (see
80
$expr is a SQL expression. It will eventually become part of a
83
@remotes contains the Remote objects (see L<Tangram::Remote>) that
84
participate in the expression. Tangram uses this list to insert the
85
corresponding tables in the FROM clause and conditions in the
88
=head1 INSTANCE METHODS
92
Returns the SQL equivalent for this expression.
96
Returns the Type (see L<Tangram::Type>) corresponding to this
101
Returns the list of the objects that participate in this
106
Returns the Storage associated with this expression.
110
$person is called 'Homer'
112
$person->{name} eq 'Homer'
114
$person's name ends with 'mer'
116
$person->{name}->like('%mer');
118
$person is older than 35
122
$person is married to $homer
124
$person->{partner} == $homer
126
$person is not $homer
130
$person is not $homer and is older than 65
132
$person != $homer & $person->{age} > 65
134
$person is $bart's parent
136
$person->{children}->includes( $bart )
137
$person->{children} < $bart
139
$person is not $bart's parent
141
!$person->{children}->includes( $bart )
142
!($person->{children} < $bart)
146
L<Tangram::Remote>, L<Tangram::Expr>, L<Tangram::Storage>
b'\\ No newline at end of file'