Name

QBit::Application::Model::DB::mysql::Table - Class for MySQL tables.

Description

Implements methods for MySQL tables.

Package methods

add

Arguments:

  • $data - reference to hash

  • %opts - additional options

    • replace - boolean (uses 'REPLACE' instead 'INSERT')

Return values:

  • $id - ID new record (returns array if primary key has more than one columns)

Example:

my $id = $app->db->users->add({login => 'Login'});

add_multi

ADD_CHUNK (records number in one statement; default: 1000)

$QBit::Application::Model::DB::mysql::ADD_CHUNK = 500;

Arguments:

  • $data - reference to array

  • %opts - additional options

    • replace - boolean

Return values:

  • $count - records number

Example:

my $count = $app->db->users->add_multi([{login => 'Login 1'}, {login => 'Login 2'}]); # $count = 2

create_sql

returns sql for create table.

No arguments.

Return values:

  • $sql - string

Example:

my $sql = $app->db->users->create_sql();

delete

Arguments:

  • $pkeys_or_filter - perl variables or object (QBit::Application::Model::DB::filter)

Example:

$app->db->users->delete(1);
$app->db->users->delete([1]);
$app->db->users->delete({id => 1});
$app->db->users->delete($app->db->filter({login => 'Login'}));

edit

Arguments:

  • $pkeys_or_filter - perl variables or object (QBit::Application::Model::DB::filter)

  • $data - reference to hash

Example:

$app->db->users->edit(1, {login => 'LoginNew'});
$app->db->users->edit([1], {login => 'LoginNew'});
$app->db->users->edit({id => 1}, {login => 'LoginNew'});
$app->db->users->edit($app->db->filter({login => 'Login'}), {login => 'LoginNew'});

replace

Same as

$app->db->users->add($data, replace => TRUE);