Query
Name
SQL::Query - An SQL query with it's arguments
Synopsis
use SQL::Query :delegate;
my $query = SQL::Query.new('SELECT ...', [1, 2, delegate('foo')]);
my $sth = $dbh.prepare($query);
for 3..5 -> $foo {
$sth.execute($query.resolve({ :$foo }));
}
Description
This abstracts over the combination of a query and its placeholder arguments.
SQL::Query
new(Str:D $sql, @arguments? --> SQL::Query)
This creates a new SQL::Query object.
sql(--> Str:D)
This returns the SQL portion of the query.
arguments(--> List)
This returns the argument list without resolving any delegate values.
resolve(%replacements --> List)
This resolves the delegate arguments in the list using %replacements and returns the result.
identifiers(--> List)
This returns all identifiers of delegate arguments.
type-hints(--> List)
This returns the expected types for the arguments.
has-delegate(--> Bool)
This returns true if any argument is delegate.
delegate values
This functionality is mainly useful when abstracting over prepared statements. A delegate value can be using three helper functions:
delegate
This takes an identifier that is later used to map the value to its substitution. It optionally takes a default value in case no substitution is provided and a type for type-hinting.
delegate(Str $identifier, Any $default?, Any:U :$type --> SQL::Query::Delegate)
delegate-pair
delegate-pair(Str $identifier, Any $default?, Any:U :$type = $default.WHAT --> Pair)
This is much like delegate, but returns a pair with the identifier as key and the delegate as value.
delegate-pairs
delegate-pairs(*@identifiers)
This returns a sequence of delegate pairs with the chosen identifiers.