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'sbindtypeto'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), andsource. Alimitparam appends aLIMIT ?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::Abstractmethod expects. Insert and delete confess on unsupportedlimit/order_byclauses. - $cond = $builder->qorm_and($a, $b)
- $cond = $builder->qorm_or($a, $b)
-
Combine two where-conditions with
SQL::Abstract's-and/-oroperators. - $formatted = $builder->_format_insert_and_update_data(\%data)
-
Wrap each value in a
{ -value => ... }soSQL::Abstracttreats it as a literal bind value rather than interpreting it.
PRIVATE METHODS
These translate caller-facing ORM column names into database column names so that generated SQL always uses database names. They build fresh structures and never mutate the caller's data. Literal SQL (scalar refs and array-of-literal refs) is left untouched, and unknown names pass through unchanged.
- $builder->_translate_params($source, \%params)
-
Rewrite the
insert,update,where,fields,returning, andorder_byparams in place (each replaced with a freshly built structure) from ORM names to database names for the given source. - $db_name = $builder->_field_to_db($source, $name)
-
Translate a single field name to its database name, leaving references (literal SQL) untouched.
- $hash = $builder->_translate_data($source, \%data)
-
Return a new data hashref with its keys translated to database names.
- $fields = $builder->_translate_fields($source, \@fields)
-
Return a new field-list arrayref with each plain-scalar field translated to its database name.
- $where = $builder->_translate_where($source, $where)
-
Recursively walk a
SQL::Abstractwhere-structure, returning a new structure with field-name hash keys translated to database names. A hash key is treated as a field when the source recognizes it; logic operators (-and,-or,-not, ...) are recursed into. Operator-expression values under a field key (e.g.{ '>' => 5 }) and value arrayrefs are left as-is. - $order = $builder->_translate_order($source, $order_by)
-
Return a new
order_bystructure with column names translated to database names. Handles a bare column, an arrayref of columns, and the{ -asc => ... }/{ -desc => ... }hash forms (where the column lives in the value). Literal SQL refs are left untouched.
SOURCE
The source code repository for DBIx::QuickORM can be found at https://github.com/exodist/DBIx-QuickORM.
MAINTAINERS
AUTHORS
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.