This plugin is a wrapper around cpp-driver.
Follow the instructions in our manual to add our package repository and then run the below command.
apt-get install halon-extras-cassandra
yum install halon-extras-cassandra
For the configuration schema, see cassandra-app.schema.json.
plugins:
- id: cassandra
config:
default_profile: cluster-1
profiles:
- id: cluster-1
hosts:
- cassandra-1
- cassandra-2
port: 9042
connect_timeout: 5000
request_timeout: 12000
resolve_timeout: 2000
connection_idle_timeout: 60
connection_heartbeat_interval: 30
tcp_keepalive: 60
core_connections_per_host: 32
num_threads_io: 1
# username: username
# password: password
tls: false
tls_verify_peer: false
tls_verify_host: false
These classes needs to be imported from the extras://cassandra
module path.
The Cassandra class is a cpp-driver wrapper class. On error an exception is thrown.
Creates a new query statement. On error an exception is thrown.
Creates a new batch statement with batch type "LOGGED"
, "UNLOGGED"
or "COUNTER"
. On error an exception is thrown.
A query statement. This class cannot be instantiated and can only be returned from other functions.
Set the paging size. On error an exception is thrown.
Check if there are more pages. On error an exception is thrown.
Execute a query statement. On error an exception is thrown. See the table below for the data types mapping.
Cassandra | HSL | Comment |
---|---|---|
ascii |
string |
|
text |
string |
|
varchar |
string |
|
bigint |
string |
|
counter |
string |
|
int |
number |
|
smallint |
number |
|
tinyint |
number |
|
float |
number |
|
double |
number |
|
inet |
string |
|
uuid |
string |
|
timeuuid |
string |
|
boolean |
boolean |
|
timestamp |
string |
|
date |
number |
|
time |
string |
|
duration |
array |
months (number ), days (number ), nanos (string ) |
blob |
string |
|
varint |
string |
|
decimal |
array |
varint (string ), scale (number ) |
map |
array |
|
list |
array |
|
set |
array |
|
tuple |
array |
|
custom |
none |
Not supported |
udt |
none |
Not supported |
Binds a boolean
to a query at the specified index. On error an exception is thrown.
Binds a blob
, varint
or custom
to a query at the specified index. On error an exception is thrown.
Binds a double
to a query at the specified index. On error an exception is thrown.
Binds a float
to a query at the specified index. On error an exception is thrown.
Binds a int8
to a query at the specified index. On error an exception is thrown.
Binds a int16
to a query at the specified index. On error an exception is thrown.
Binds a int32
to a query at the specified index. On error an exception is thrown.
Binds a int64
to a query at the specified index. On error an exception is thrown.
Binds a uint32
to a query at the specified index. On error an exception is thrown.
Binds a decimal
to a query at the specified index. On error an exception is thrown.
Binds a inet
to a query at the specified index. On error an exception is thrown.
Binds a null
to a query at the specified index. On error an exception is thrown.
Binds a string
to a query at the specified index. On error an exception is thrown.
Binds a uuid
to a query at the specified index. On error an exception is thrown.
Binds a duration
to a query at the specified index. On error an exception is thrown.
A batch statement. This class cannot be instantiated and can only be returned from other functions.
Creates a new query statement. On error an exception is thrown.
Execute a batch statement. On error an exception is thrown.
import { Cassandra } from "extras://cassandra";
// Create "Cassandra" instance with an (optional) config profile
$cassandra = Cassandra("cluster-1");
// "CREATE" query statement
$cassandra->statement("CREATE KEYSPACE IF NOT EXISTS foo WITH REPLICATION = {'class':'NetworkTopologyStrategy','datacenter1':2};")->execute();
$cassandra->statement("CREATE TABLE IF NOT EXISTS foo.bar (id UUID PRIMARY KEY);")->execute();
// "INSERT" query statement with parameter binding
$statement = $cassandra->statement("INSERT INTO foo.bar (id) VALUES (?);", 1);
$statement->bind_uuid(0, uuid());
$statement->execute();
// "SELECT" query statement
echo $cassandra->statement("SELECT * FROM foo.bar;")->execute();
// "INSERT" batch statement
$batch = $cassandra->batch("LOGGED");
$statement = $batch->statement("INSERT INTO foo.bar (id) VALUES (?);", 1);
$statement->bind_uuid(0, uuid());
$statement = $batch->statement("INSERT INTO foo.bar (id) VALUES (?);", 1);
$statement->bind_uuid(0, uuid());
$statement = $batch->statement("INSERT INTO foo.bar (id) VALUES (?);", 1);
$statement->bind_uuid(0, uuid());
$batch->execute();
// "SELECT" query statement with pagination
$rows = [];
$statement = $cassandra->statement("SELECT * FROM foo.bar");
$statement->paging_size(2);
while ($statement->has_more_pages())
$rows = $statement->execute();
echo $rows;