SimpleDB::Class::SQL - SQL generation tools for SimpleDB.
version 1.0503
This class is used to generate the SQL needed for the Select operation on SimpleDB's web service.
The following methods are available from this class.
Constructor.
A hash of options you can pass in to the constructor.
A SimpleDB::Class::Item subclass name. This is required.
A reference to the SimpleDB::Class object. This is required.
Defaults to '*'. Alternatively you can pass a string of 'count(*)' or an attribute. Or you can pass an array ref of attributes.
A hash reference containing a series of clauses. Here are some examples and what the resulting queries would be. You can of course combine all these options to create your own queries.
NOTE: If you want to search on an item's id (or ItemName) then you should use the itemName() function as the id doesn't actually exist in the item's data.
itemName()
Direct comparison.
{ foo => 1 } select * from domain where foo=1 { foo => 1, bar => 2 } select * from domain where foo=1 and bar=2 { foo => [ '>', 5 ] } # '=', '!=', '>', '<', '<=', '>=' select * from domain where foo > 5
Direct comparison with an or clause.
{ -or => { foo => 1, bar => 2 } } select * from domain where (foo=1 or bar=2)
Find all items where these attributes intersect.
{ -intersection => { foo => 1, bar => 2 } } select * from domain where (foo=1 intersection bar=2)
Combining OR and AND.
{ -or => { foo => 1, -and => { this => 'that', bar => 2 } } select * from domain where (foo=1 or ( this='that' and bar=2 ))
Finding within a range.
{ foo=>['between', 5, 10] } select * from domain where foo between 5 and 10
Finding within a set.
{ foo => ['in', 1, 3, 5, 7 ] } select * from domain where foo in (1, 3, 5, 7)
Finding in a set where every item returned matches all members of the set.
{ foo => ['every', 1, 3, 5, 7 ] } select * from domain where every(foo) in (1, 3, 5, 7)
String comparisons. You can match on either side of the string ('%this', 'that%') or both ('%this%'). Note that matching at the beginning or both sides of the string is a slow operation.
{ foo => [ 'like', 'this%' ] } # 'not like' select * from domain where foo like 'this%'
Null comparisons. These are very slow. Try inserting 'Null' or 'None' into a field and do string comparisons rather than null comparisons.
{ foo => 'is null' } # 'is not null' select * from domain where foo is null
An attribute to order the result set by, defaults to ascending order. Can also pass in an array ref containing an attribute and 'desc' or 'asc'. If an array ref is passed in containing only an attribute name it is an implied descending order.
"foo" ["foo","desc"] ["foo"]
An integer of a number of items to limit the result set to.
Returns what was passed into the constructor for the output field.
Returns the reference passed into the constructor.
Returns what was passed into the constructor for the item_class field.
Returns what was passed into the constructor for the where field.
Returns a boolean indicating whether a where clause has been set.
Returns a boolean indicating whether an order by clause has been set.
Escapes ' and " in values. If itemName() is what's passed in, it will not be quoted.
The value to escape.
Escapes an attribute with so that it can contain spaces and other special characters by wrapping it in backticks `. If itemName() is what's passed in, it will not be quoted.
The attribute name to escape.
Traverses a where() hierarchy and returns a stringified SQL version of the where clause.
A portion of a where hierarchy, perhaps broken off from the main for detailed analysis.
If it's a chunk broken off, -and, -or, -intersection then the operator will be passed through here.
Returns the entire query as a stringified SQL version.
SimpleDB::Class is Copyright 2009-2010 Plain Black Corporation (http://www.plainblack.com/) and is licensed under the same terms as Perl itself.
To install SimpleDB::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SimpleDB::Class
CPAN shell
perl -MCPAN -e shell install SimpleDB::Class
For more information on module installation, please visit the detailed CPAN module installation guide.