NAME

CatalystX::CRUD::Model::Utils - helpful methods for your CRUD Model class

SYNOPSIS

package MyApp::Model::Foo;
use base qw( 
   CatalystX::CRUD::Model
   CatalystX::CRUD::Model::Utils
 );
# ... 
1;

DESCRIPTION

CatalystX::CRUD::Model::Utils provides helpful, non-essential methods for CRUD Model implementations. Stick it in your @ISA to help reduce the amount of code you have to write yourself.

METHODS

use_ilike( boolean )

Convenience accessor to flag requests in params_to_sql_query() to use ILIKE instead of LIKE SQL command.

ne_sign( string )

What string to use for 'not equal' in params_to_sql_query(). Defaults to '!='.

treat_like_int

Should return a hashref of column names to treat as integers instead of text strings when parsing wildcard request params. Example might be all date/timestamp columns.

make_sql_query( [ field_names ] )

Returns a hashref suitable for passing to a SQL-oriented model.

field_names should be an array of valid column names. If false or missing, will call $c->controller->field_names().

The following reserved request param names are implemented:

cxc-order

Sort order. Should be a SQL-friendly string parse-able by Sort::SQL.

cxc-sort

Instead of cxc-order, can pass one column name to sort by.

cxc-dir

With cxc-sort, pass the direction in which to sort.

cxc-page_size

For the Data::Pageset pager object. Defaults to page_size(). An upper limit of 200 is implemented by default to reduce the risk of a user [unwittingly] creating a denial of service situation.

cxc-page

What page the current request is coming from. Used to set the offset value in the query. Defaults to 1.

cxc-offset

Pass explicit row to offset from in query. If not present, deduced from cxc-page and cxc-page_size.

cxc-no_page

Ignore cxc-page_size, cxc-page and cxc-offset and do not return a limit or offset value.

cxc-op

If set to OR then the query columns will be marked as OR'd together, rather than AND'd together (the default).

cxc-query

The query string to use. This overrides any param values set for field names.

cxc-query-fields

Which field names to set as 'default_column' in the Search::QueryParser::SQL parser object. The default is all field_names. NOTE this param is only checked if cxc-query has a value.

cxc-fuzzy

If set to a true value triggers the 'fuzzify' feature in Search::QueryParser::SQL.

cxc-fuzzy2

If set to a true value, overrides cxc-fuzzy and triggers the 'fuzzify2' feature in Search::QueryParser::SQL.

params_to_sql_query( field_names )

Convert request->params into a SQL-oriented query.

Returns a hashref with three key/value pairs:

sql

Arrayref of ORM-friendly SQL constructs.

query_hash

Hashref of column_name => raw_values_as_arrayref.

query

The Search::QueryParser::SQL::Query object used to generate sql.

Called internally by make_sql_query().

make_pager( total )

Returns a Data::Pageset object using total, either the _page_size param or the value of page_size(), and the _page param or 1.

If the _no_page request param is true, will return undef. NOTE: Model authors should check (and respect) the _no_page param when constructing queries.

AUTHOR

Peter Karman, <perl at peknet.com>

BUGS

Please report any bugs or feature requests to bug-catalystx-crud at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc CatalystX::CRUD

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2007 Peter Karman, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.