Fey::Literal::Term - Represents a literal term in a SQL statement
my $term = Fey::Literal::Term->new(@anything)
This class represents a literal term in a SQL statement. A "term" in this module means a literal SQL snippet that will be used verbatim, without quoting.
This allows you to create SQL for almost any expression, for example
EXTRACT( DOY FROM TIMESTAMP "User.creation_date" ), which is a valid Postgres expression. This would be created like this:
my $term = Fey::Literal::Term->new ( 'DOY FROM TIMESTAMP ', $column ); my $function = Fey::Literal::Function->new( 'EXTRACT', $term );
This ability to insert arbitrary strings into a SQL statement is meant to be used as a back-door to support any sort of SQL snippet not otherwise supported by the core Fey classes in a more direct manner.
This module is a subclass of
This class provides the following methods:
This method creates a new
Fey::Literal::Term object representing the term passed to the constructor.
More than one argument may be given; they will all be joined together in the generated SQL. For example:
my $term = Fey::Literal::Term->new( $column, '::text' );
The arguments can be plain scalars, objects with a
sql_or_alias() method (columns, tables, etc.) or any object which is overloaded (the assumption being it that it overloads stringification).
Returns the array reference of fragments passed to the constructor.
If this attribute is explicitly set to a false value, then then the SQL-generating methods below will never include an alias.
The id for a term is uniquely identifies the term.
Returns the appropriate SQL snippet. If the term contains any Fey objects, their
sql_or_alias() method is called to generate their part of the term.
A term generates SQL by taking each of the elements passed to its constructor and concatenating them. If the element is an object with a
sql_or_alias() method, that method will be called to generate SQL. Otherwise, the element is just used as-is.
$term->can_have_alias() is false, then calling any of the three SQL-generating methods is always equivalent to calling
This class does the
Of course, the contents of a given term may not really allow for any of these things, but having this class do these roles means you can freely use a term object in any part of a SQL snippet.
See Fey for details on how to report bugs.
Dave Rolsky <email@example.com>
This software is Copyright (c) 2011 - 2015 by Dave Rolsky.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)