DBD::Cassandra - Database driver for Cassandra's CQL3
use DBI; my $dbh = DBI->connect("dbi:Cassandra:host=localhost;keyspace=test", $user, $password, { RaiseError => 1 }); my $rows = $dbh->selectall_arrayref("SELECT id, field_one, field_two FROM some_table"); for my $row (@$rows) { # Do something with your row } $dbh->do("INSERT INTO some_table (id, field_one, field_two) VALUES (?, ?, ?)", { Consistency => "quorum", Retries => 1 }, 1, "String value", 38962986 ); $dbh->disconnect;
DBD::Cassandra is a Perl5 Database Interface driver for Cassandra, using the CQL3 query language.
use DBI; $dsn = "dbi:Cassandra:database=$database"; $dsn = "dbi:Cassandra:keyspace=$keyspace;host=$hostname;port=$port"; $dsn = "dbi:Cassandra:keyspace=$keyspace;consistency=local_quorum";
Optionally, a keyspace to use by default. If this is not specified, all queries must include the keyspace name.
Hostname to connect to. Defaults to localhost
localhost
Port number to connect to. Defaults to 9042
9042
The compression method we should use for the connection. Currently Cassandra allows lz4 and snappy. Defaults to the algorithm with the best compression ratio, if the server supports it. Compression can be disabled by setting compression=none.
lz4
snappy
compression=none
Only used for data frames longer than 512 bytes, smaller frames get sent uncompressed.
There are several versions of the CQL language and this option lets you pick one. Defaults to the highest available version. Consult your Cassandra manual to see which versions your database supports.
$dbh->do("INSERT INTO some_table (id, field_name) VALUES (?, ?)", { Consistency => "quorum" }, @values );
DBD::Cassandra accepts a Consistency attribute for statements. Supported consistency levels are any, one, two, three, quorum, all, local_quorum, each_quorum, serial, local_serial and local_one.
any
one
two
three
quorum
all
local_quorum
each_quorum
serial
local_serial
local_one
This attribute is ignored on statements that do not support it, such as CREATE.
CREATE
A global consistency level can be defined as part of the DSN.
There is currently no support for transactions. begin_work will die if you try to use it.
begin_work
Thread support is untested. Use at your own risk.
There is currently no support for asynchronous queries, and there are no plans to implement it. If you need to run a lot of queries in parallel, consider using fork to manage the parallel work.
fork
Not all Cassandra data types are supported. These are currently supported:
ascii
bigint
blob
boolean
custom
double
float
int
text
timestamp
varchar
Cassandra/CQL3 is strict about the queries you write. When switching from other databases, such as MySQL, this may come as a surprise. This module supports quote(..), but try to use prepared statements instead. They will save you a lot of trouble.
quote(..)
This module is released under the same license as Perl itself.
Tom van der Woerdt, tvdw@cpan.org
To install DBD::Cassandra, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBD::Cassandra
CPAN shell
perl -MCPAN -e shell install DBD::Cassandra
For more information on module installation, please visit the detailed CPAN module installation guide.