NAME
Ambrosia::QL - a Query Language to data source.
VERSION
version 0.010
SYNOPSIS
use Ambrosia::QL;
#get all rows from table tClient in data source described by to words
#'DBI' (type of source) and 'Client' (name of source)
my @r1 = Ambrosia::QL
->from('tClient')
->in(storage()->driver('DBI', 'Client'))
->what(qw/LastName FirstName MiddleName Age/)
->select()
->take();
#get one row from table tClient in data source described by to words
#'DBI' (type of source) and 'Client' (name of source)
#and where ClientId is 22
my @r = Ambrosia::QL
->from('tClient')
->in(storage()->driver('DBI', 'Client'))
->what(qw/LastName FirstName MiddleName Age/)
->predicate('ClientId', '=', 22)
->select()
->take(1);
#get one row from table tClient in data source described by to words
#'DBI' (type of source) and 'Client' (name of source)
#and that have been tested in 'checkClient'
my @r = Ambrosia::QL
->from('tClient')
->in(storage()->driver('DBI', 'Client'))
->what(qw/LastName FirstName MiddleName Age/)
->predicate(\&checkClient)
->select()
->take(1);
DESCRIPTION
Ambrosia::QL
is a query language for getting data from data source provided by Ambrosia::DataProvider.
CONSTRUCTOR
from (tableName, referenceToVariable)
- tableName
-
Name of the table which is a source of data.
- referenceToVariable
-
Optional. Reference to a variable. This variable can be subsequently used in the select method as a hash.
METHODS
in (driver)
Set data of sorce.
what (@_)
Describe what columns you want to get from data source.
$ql->what(qw/Name Age/);
$ql->what();
If parameters not present then whil select all columns.
predicate (ColumnName, Operation, Value)
You can use this method in two ways:
- Pointing to two or three parameters.
-
In this case, the processing of a predicate will be carried out on the side of the driver
$ql->predicate('Name', '=', 'John'); $ql->predicate('Name', '=', 'John') ->predicate('Age', '<', 42); This means that the rows will be selected in which the column Name is "John" and Age less than 42 $ql->predicate(['Name', '=', 'John'],['Name', '=', 'Jack']); This means that the rows will be selected in which the column Name is "John" or "Jack"
Value is optional. So you can write: $ql->predicate('Name', 'IS NOT NULL')
- Pointing to subrutine.
-
$ql->predicate(sub { shift()->{tableName_columnName} =~ /^Jo/ });
This procedure is passed a hash whose keys are of the form "tableName_columnName" if you use method "what" in Ambrosia::QL and "columnName" if you not use method "what" in Ambrosia::QL.
You can also combine calling some this methods. $ql->predicate(sub { shift()->{table_Name} =~ /^Jo/ }) ->predicate(sub { shift()->{table_Age} == 42 });
That conjunction of predicates.
select (subrutine)
You can call this method, indicating the subroutine for rows processing.
my $client;
my @r = Ambrosia::QL
->from('tClient', \$client)
->in(storage()->driver('DBI', 'Client'))
->what(qw/LastName FirstName MiddleName Age/)
->predicate(sub{
shift->{tClient_Age} == 42})
->select(sub {
return {map { my $k = $_; $k =~ s/^tClient_//; $k => $client->{$_}; } keys %$client};
})
->take(1);
#now @r contained
#(
# {
# LastName => 'LastName22',
# FirstName => 'FirstName22',
# MiddleName => 'MiddleName22',
# Age => 42,
# },
#);
take ($count)
This method returns a specified number ($count
) of records from a data source and destroys the request object. If $count is undefined then will returned all rows.
skip ($count)
This method specifies how many rows should pass before starting to produce results.
next
Return next row from source of data or return nothing if relevant rows not found more. After use the next
you must call destroy
.
my $ql = Ambrosia::QL
->from('tClient')
->in(storage()->driver('DBI', 'Client'))
->what(qw/LastName FirstName MiddleName Age/)
->predicate('Age', '=', 42);
my @r = ();
while(my $r = $ql->next() )
{
push @r, $r;
}
$ql->destroy();
destroy
Destroys the object and frees up resources.
THREADS
Not tested.
BUGS
Please report bugs relevant to Ambrosia
to <knm[at]cpan.org>.
COPYRIGHT AND LICENSE
Copyright (C) 2010-2012 Nickolay Kuritsyn. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Nikolay Kuritsyn (knm[at]cpan.org)