Name
QBit::QueryData - Query constructor for the data.
GitHub
https://github.com/QBitFramework/QBit-QueryData
Install
cpanm QBit::QueryData
apt-get install libqbit-querydata-perl (http://perlhub.ru/)
Methods
new - created object. Params:
data - data.
fields - default fields (optional, defualt all fields)
filter - default filter (optional, default all data)
definition - fields definition (optional, default 'string')
Example:
my $q = QBit::QueryData->new( data => [ { id => 1, caption => 'c1' }, { id => 2, caption => 'c2' }, ], fields => [qw(id caption)], filter => ['OR', [{id => 1}, ['caption' => '=' => \'c2']]], definition => { id => {type => 'number'}, caption => {type => 'string'} }, );
fields - set fields for request
Example:
$q->fields([qw(caption)]); # or $q->fields({caption => ''}); $q->fields([]); # use default fields $q->fields(); # all fields
get_fields - get fields
Example:
my $fields = $q->get_fields(); # ['caption', 'id']
filter - set filter for request
Types:
number: =, <>, !=, >. >=, <, <=, IN, NOT IN, IS, IS NOT
string: =, <>, !=, >. >=, <, <=, IN, NOT IN, IS, IS NOT, LIKE, NOT LIKE
Example:
$q->filter({id => 1, caption => 'c1'}); # or ['AND', [['id' => '=' => \1], ['caption' => '=' => \'c1']]] $q->filter(['caption' => 'LIKE' => \'c']); $q->filter(); # all data
definition - set fields definition
Example:
$q->definition({ id => {type => 'number'}, caption => {type => 'string'} });
order_by - set order sorting
Example:
# Ascending $q->order_by(qw(id caption)); # or (['id', 0], ['caption', 0]) # Descending $q->order_by(['id', 1]);
limit - set offset and limit
Example:
$q->limit($offset, $limit); $q->limit(); # all data
found_rows - data count
Example:
my $rows = $q->found_rows(); # 2
distinct - set/reset only unique elements
Example:
#set $q->distinct(1); # or $q->distinct(); #reset $q->distinct(0);
insensitive - set/reset insensitive mode for LIKE
Example:
#set $q->insensitive(1); # or $q->insensitive(); #reset $q->insensitive(0);
get_all - get data by settings
Example:
my $data = $q->get_all(); $data = $q->fields([qw(id)])->filter(['caption' => 'LIKE' => \'c'])->order_by(['id', 1])->get_all();
all_langs - support interface DB::Query
calc_rows - support interface DB::Query
for_update - support interface DB::Query