Fey::Literal::Term(3)

NAME
Fey::Literal::Term - Represents a literal term in a SQL statement

VERSION
version 0.44

SYNOPSIS
  my $term = Fey::Literal::Term->new(@anything)

DESCRIPTION
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.

INHERITANCE
This module is a subclass of "Fey::Literal".

METHODS
This class provides the following methods:

  Fey::Literal::Term->new(@fragments)
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).

  $term->term()
Returns the array reference of fragments passed to the constructor.

  $term->can_have_alias()

  $term->set_can_have_alias()
If this attribute is explicitly set to a false value, then then the SQL-generating methods below will never include an alias.

  $term->id()
The id for a term is uniquely identifies the term.

  $term->sql()

  $term->sql_with_alias()

  $term->sql_or_alias()
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.

DETAILS OF SQL GENERATION
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.

If "$term->can_have_alias()" is false, then calling any of the three SQL-generating methods is always equivalent to calling "$term->sql()".

ROLES
This class does the "Fey::Role::Selectable", "Fey::Role::Comparable", "Fey::Role::Groupable", and "Fey::Role::Orderable" roles.

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.

BUGS
See Fey for details on how to report bugs.

Bugs may be submitted at <https://github.com/ap/Fey/issues>.

SOURCE
The source code repository for Fey can be found at <https://github.com/ap/Fey>.

AUTHOR
Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE
This software is Copyright (c) 2011 - 2025 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)

The full text of the license can be found in the LICENSE file included with this distribution.