AnyEvent-ClickHouse
view release on metacpan or search on metacpan
lib/AnyEvent/ClickHouse.pm view on Meta::CPAN
$headers->{'Connection'} = 'Keep-Alive';
sub _init {
my $param = shift;
my %_param = (
host => '127.0.0.1',
port => 8123,
database => 'default',
user => undef,
password => undef
);
foreach my $_key ( keys %_param ) {
unless ($param->{$_key}){
$param->{$_key} = $_param{$_key};
}
}
unless ($param->{uri}) {
my $_uri = URI->new(sprintf ("http://%s:%d/",$param->{host},$param->{port}));
$_uri->query_param('user' => $param->{user}) if $param->{user};
$_uri->query_param('password' => $param->{password}) if $param->{password};
$_uri->query_param('database' => $param->{database});
$param->{uri} = $_uri;
}
return $param;
}
sub _data_prepare {
my $self = shift;
my @_rows = map { [@$_] } @_;
lib/AnyEvent/ClickHouse.pm view on Meta::CPAN
=head1 SYNOPSIS
use AnyEvent::ClickHouse;
clickhouse_select
{ # connection options
host => '127.0.0.1',
port => 8123,
user => 'Harry',
password => 'Alohomora',
database => 'Hogwarts'
},
'select * from test FORMAT Pretty', # query
sub { # callback function if status ok 200
my $data = shift;
},
sub { # callback function if status error 500
my $data = shift;
}
;
lib/AnyEvent/ClickHouse.pm view on Meta::CPAN
=item * ...
=back
L<https://clickhouse.yandex/reference_en.html#Formats>
clickhouse_select
{
host => '127.0.0.1',
user => 'Harry',
password => 'Alohomora'
},
'select * from test',
sub { # callback function if status ok 200
my $data = shift;
# ... do something
# print $data;
},
sub { # callback function if status error 500
my $data = shift;
lib/AnyEvent/ClickHouse.pm view on Meta::CPAN
}
;
You can use URI
use URI;
use URI::QueryParam;
my $uri = URI->new(sprintf ("http://%s:%d/",'127.0.0.1',8123)); # host and port
$uri->query_param('user' => 'Harry');
$uri->query_param('password' => 'Alohomora');
$uri->query_param('database' => 'default');
clickhouse_select
{
uri => $uri
},
...
=head2 clickhouse_do
Universal method for any queries inside the database,
which modify data (insert data, create, alter, detach or drop table or partition).
clickhouse_do
{
host => '127.0.0.1',
user => 'Harry',
password => 'Alohomora'
},
"INSERT INTO test (id, f1, f2) VALUES",
sub { # callback function if status ok 200
my $data = shift;
# do something
},
undef, # You can skip callback function
[1, "Gryffindor", "a546825467 1861834657416875469"],
[2, "Hufflepuff", "a18202568975170758 46717657846"],
[3, "Ravenclaw", "a678 2527258545746575410210547"],
lib/AnyEvent/ClickHouse.pm view on Meta::CPAN
Fetch data from the table (readonly).
It returns a reference to an array that contains a references to an arrays for each row of data fetched.
Don't use FORMAT in query!
clickhouse_select_array
{
host => '127.0.0.1',
user => 'Harry',
password => 'Alohomora'
},
'select * from test',
sub { # callback function if status ok 200
my $data = shift;
# ... do something
# foreach my $row (@$data) {
# # Do something with your row
# foreach my $col (@$row) {
lib/AnyEvent/ClickHouse.pm view on Meta::CPAN
Fetch data from the table (readonly).
Returns a reference to an array that contains a hashref to the names of the columns (as keys)
and the data itself (as values).
Don't use FORMAT in query!
clickhouse_select_hash
{
host => '127.0.0.1',
user => 'Harry',
password => 'Alohomora'
},
'select * from test',
sub { # callback function if status ok 200
my $data = shift;
# ... do something
# foreach my $row (@$data) {
# # Do something with your row
# foreach my $key (keys %{$row}){
( run in 0.994 second using v1.01-cache-2.11-cpan-49f99fa48dc )