NAME

DBIx::QuickORM::LiteralSource - A raw SQL fragment used as a query source.

DESCRIPTION

A source (see DBIx::QuickORM::Role::Source) backed by a literal SQL string rather than a table, view, or join. The object is a blessed scalar reference holding the SQL; source_db_moniker returns that SQL verbatim.

The SQL is spliced in as the FROM target of the generated statement, so by default it must be a table name or FROM-fragment (for example users or users AS u), not a complete SELECT statement. A full statement produces broken SQL (SELECT * FROM SELECT ...).

To query a complete statement, pass the subquery option: the SQL is wrapped as a derived table, ( <sql> ) AS <alias>, where the alias is the value of subquery:

# SELECT * FROM ( SELECT ... ) AS recent
my $src = DBIx::QuickORM::LiteralSource->new($full_select, subquery => 'recent');

Literal sources carry no schema metadata: they expose no fields, no primary key, and no row class, so the field/key accessors return nothing and the source is not cachable. fields_to_fetch is ['*'].

SYNOPSIS

# FROM-fragment (table name)
my $source = DBIx::QuickORM::LiteralSource->new("users");

# Full statement wrapped as a derived table
my $sub = DBIx::QuickORM::LiteralSource->new(
    "SELECT * FROM users WHERE active = 1",
    subquery => 'active_users',
);

SOURCE

The source code repository for DBIx::QuickORM can be found at https://github.com/exodist/DBIx-QuickORM.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See https://dev.perl.org/licenses/