PHP code example of sachoo / phalcon-cassandra

1. Go to this page and download the library: Download sachoo/phalcon-cassandra library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sachoo / phalcon-cassandra example snippets


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

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

$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);
});


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;
}
bash
php composer.phar install