Name

QBit::Application::Model::DB::clickhouse::Table - Class for ClickHouse tables.

Description

Implements methods for ClickHouse tables.

Package methods

add

Arguments:

  • $data - reference to hash

  • %opts - additional options

    • fields - array ref (order for fields)

Return values:

  • $count - number of new records

Example:

my $count = $app->db->stat->add({date => '2017-09-03', hits => 10}); # $count = 1, insert all fields

$count = $app->db->stat->add({date => '2017-09-03', hits => 10, not_exists => 'something'}, fields => [qw(date hits)]);
# $count = 1, insert only date and hits in this order

add_multi

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

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

Arguments:

  • $data - reference to array

  • %opts - additional options

    • fields - array ref (order for fields)

    • identical_rows - boolean (true: get field names from first row, false: Unites all fields from all rows; default: false)

    • ignore_extra_fields - boolean (true: ignore field names that not exists in table, false: throw exception; default: false)

Return values:

  • $count - records number

Example:

my $count = $app->db->stat->add_multi([{date => '2017-09-02', hits => 5}, {date => '2017-09-03', hits => 10}]); # $count = 2

$count = $app->db->stat->add_multi([
    {date => '2017-09-02', hits => 5, not_exists => 'something'},
    {date => '2017-09-03', hits => 10, not_exists => 'something'}
  ],
  fields => [qw(date hits)]
);
# $count = 2, insert only date and hits in this order

create_sql

returns sql for create table.

No arguments.

Return values:

  • $sql - string

Example:

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