2017 © Pedro Peláez
 

library phalcon-cassandra

Cassandra library for Phalcon

image

sachoo/phalcon-cassandra

Cassandra library for Phalcon

  • Thursday, February 22, 2018
  • by sachoo
  • Repository
  • 3 Watchers
  • 7 Stars
  • 1,160 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 5 Versions
  • 39 % Grown

The README.md

Cassandra library for Phalcon

status, (*1)

Requirements

  • PHP >= 5.3
  • Cassandra php driver https://github.com/datastax/php-driver
  • Phalcon >= 3.0 https://github.com/phalcon/cphalcon/

Cassandra php driver (https://github.com/datastax/php-driver) hasn't appropriate version number. The only version number available is for C/C++ driver version (wich is not the version of the extension itself). Because of it, version of this library follow the cassandra php-driver real version., (*2)

If you need to use cassandra php-driver v1.2.2, please install our library at 1.2.2 Follow the exact same logic for other available versions., (*3)

Installing via Composer

Install composer in a common location or in your project:, (*4)

curl -s http://getcomposer.org/installer | php

Create the composer.json file as follows:, (*5)

{
    "require-dev": {
        "sachoo/phalcon-cassandra": "1.3.0"
    }
}

Run the composer installer:, (*6)

php composer.phar install

How to use

First of all you have to add and define some conf in your phalcon config file, (*7)

return new \Phalcon\Config([
    'cassandra' => [
        'adapter' => 'Cassandra',
        'hosts' => [ 'localhost'],
        'keyspace' => 'lobs',
        'consistency' => 'ONE', // Infos here \cassandra\ConsistencyLevel
        'retryPolicies' => 'DefaultPolicy',
    ]
]);

Then, you have to declare Cassandra service in your dependency injector :, (*8)

/**
 * This service returns a Cassandra database
 */
$di->setShared('dbCassandra', function () {
    $config = $this->getConfig();
    $connection = new \Phalcon\Db\Adapter\Cassandra($config->cassandra->toArray());
    return $connection;
});

IMPORTANT, if you are using mysql too, you have to change the name of mysql service in dbMysql. For exemple:, (*9)

$di->setShared('dbMysql', function () {
    $config = $this->getConfig();
    $params = [
        'host' => $config->mysql->host,
        'port' => isset($config->mysql->port) ? $config->mysql->port : 3306,
        'username' => $config->mysql->username,
        'password' => $config->mysql->password,
        'dbname' => $config->mysql->dbname,
        'charset' => $config->mysql->charset
    ];
    return new \Phalcon\Db\Adapter\Pdo\Mysql($params);
});

Then, you just have to declare the correct database service to your models in @Source annotation. For exemple:, (*10)

<?php
namespace Models\Cassandra;

/**
 * Class Article
 * @package Models\Cassandra
 *
 * @Source('dbCassandra', 'article')
 */
class Article extends \Phalcon\Mvc\CassandraModel
{
    /**
     * @Primary
     * @Column(type="uuid", nullable=false)
     */
    public $uuid;

    /**
     * @Column(type="varchar", nullable=false)
     */
    public $title;

    /**
     * @Column(type="varchar", nullable=false)
     */
    public $description;

    /**
     * list<uuid>
     * uuid of linked articles
     * @Column(type="list", nullable=true)
     */
    public $links;

    /**
     * @Column(type="float", nullable=true)
     */
    public $lat;

    /**
     * @Column(type="float", nullable=true)
     */
    public $lon;

    /**
     * @Column(type="int", nullable=true)
     */
    public $radius;

    /**
     * @Column(type="varchar", nullable=false)
     */
    public $status;

    /**
     * @Column(type="varchar", nullable=false)
     */
    public $type;

    /**
     * @Column(type="varchar", nullable=false)
     */
    public $language;
}

The Versions

22/02 2018

dev-master

9999999-dev

Cassandra library for Phalcon

  Sources   Download

MIT

The Requires

 

The Development Requires

database nosql driver cassandra phalcon datastax

21/02 2018

1.3.2

1.3.2.0

Cassandra library for Phalcon

  Sources   Download

MIT

The Requires

 

The Development Requires

database nosql driver cassandra phalcon datastax

29/06 2017

1.3.1

1.3.1.0

Cassandra library for Phalcon

  Sources   Download

MIT

The Requires

 

The Development Requires

database nosql driver cassandra phalcon datastax

23/03 2017

1.3.0

1.3.0.0

Cassandra library for Phalcon

  Sources   Download

MIT

The Requires

 

database nosql driver cassandra phalcon datastax

20/03 2017

1.2.2

1.2.2.0

Cassandra library for Phalcon

  Sources   Download

MIT

The Requires

 

database nosql driver cassandra phalcon datastax