Ambrosia::QL - a Query Language to data source.
version 0.010
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);
Ambrosia::QL is a query language for getting data from data source provided by Ambrosia::DataProvider.
Ambrosia::QL
Name of the table which is a source of data.
Optional. Reference to a variable. This variable can be subsequently used in the select method as a hash.
Set data of sorce.
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.
You can use this method in two ways:
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')
$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.
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, # }, #);
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.
$count
This method specifies how many rows should pass before starting to produce results.
Return next row from source of data or return nothing if relevant rows not found more. After use the next you must call destroy.
next
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();
Destroys the object and frees up resources.
Not tested.
Please report bugs relevant to Ambrosia to <knm[at]cpan.org>.
Ambrosia
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.
Nikolay Kuritsyn (knm[at]cpan.org)
To install Ambrosia, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Ambrosia
CPAN shell
perl -MCPAN -e shell install Ambrosia
For more information on module installation, please visit the detailed CPAN module installation guide.