NAME

DBIx::QuickORM::SQLBuilder::SQLAbstract - SQL builder backed by SQL::Abstract.

DESCRIPTION

An implementation of the SQL builder role (see DBIx::QuickORM::Role::SQLBuilder) built on top of SQL::Abstract. It takes ORM source objects and parameter hashes and produces statement-plus-bind structures the ORM can execute.

For each of insert, update, select, delete, and where it provides a qorm_* method that resolves the source to its db moniker, builds the statement via the corresponding SQL::Abstract method, and normalizes the bind list into per-field bind specs. qorm_upsert extends an insert with a dialect-specific conflict clause.

SYNOPSIS

my $builder = DBIx::QuickORM::SQLBuilder::SQLAbstract->new;

my $sql = $builder->qorm_select(
    source => $source,
    fields => $fields,
    where  => \%where,
);

my ($statement, $bind) = @{$sql}{qw/statement bind/};

PUBLIC METHODS

$builder = DBIx::QuickORM::SQLBuilder::SQLAbstract->new(%args)

Construct a builder. Forces SQL::Abstract's bindtype to 'columns' so binds carry their field names.

$sql = $builder->qorm_insert(source => $source, ...)
$sql = $builder->qorm_update(source => $source, ...)
$sql = $builder->qorm_select(source => $source, ...)
$sql = $builder->qorm_delete(source => $source, ...)
$sql = $builder->qorm_where(source => $source, ...)

Build a statement of the named kind for the given source. Each returns a hashref with statement, bind (an arrayref of per-field bind specs), and source. A limit param appends a LIMIT ? clause. These methods are generated at compile time.

$sql = $builder->qorm_upsert(source => $source, insert => \%data, ...)

Build an insert and append the dialect's upsert/conflict clause keyed on the source's primary key, with the non-key fields as the update set. Croaks if the source has no primary key.

@args = $builder->_insert_args(\%params)
@args = $builder->_update_args(\%params)
@args = $builder->_select_args(\%params)
@args = $builder->_delete_args(\%params)
@args = $builder->_where_args(\%params)

Translate the ORM parameter hash into the positional argument list the corresponding SQL::Abstract method expects. Insert and delete confess on unsupported limit / order_by clauses.

$cond = $builder->qorm_and($a, $b)
$cond = $builder->qorm_or($a, $b)

Combine two where-conditions with SQL::Abstract's -and / -or operators.

$formatted = $builder->_format_insert_and_update_data(\%data)

Wrap each value in a { -value => ... } so SQL::Abstract treats it as a literal bind value rather than interpreting it.

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/