GithubHelp home page GithubHelp logo

kmarkow / php-cassandra-binary Goto Github PK

View Code? Open in Web Editor NEW

This project forked from evseevnn-zz/php-cassandra-binary

0.0 0.0 0.0 190 KB

PHP library for Cassandra database via a binary protocol.

Home Page: http://evseevnn.github.io/php-cassandra-binary/

License: MIT License

PHP 100.00%

php-cassandra-binary's Introduction

PHP library for Cassandra

Build Status

Cassandra client library for PHP, using the native binary protocol.

Roadmap for version 0.2.0

  • UUID generation
  • timestamp only with microsecond
  • using v2 protocol
  • speedup
  • the ability to specify the settings (setup default consistency level and more)
  • more fixes

Known issues

  • decimal and timestamps have bugs especially in collections (map,set,list)
  • connection handling e.g. timeouts

Installation

PHP 5.4+ is required. There is no need for additional libraries.

Append dependency into composer.json

	...
	"require": {
		...
		"evseevnn/php-cassandra-binary": "dev-master"
	}
	...

Base Using

<?php

$nodes = [
	'127.0.0.1',
	'192.168.0.2:8882' => [
		'username' => 'admin',
		'password' => 'pass'
	]
];

// Connect to database.
$database = new evseevnn\Cassandra\Database($nodes, 'my_keyspace');
$database->connect();

// Run query.
$users = $database->query('SELECT * FROM "users" WHERE "id" = :id', ['id' => 'c5420d81-499e-4c9c-ac0c-fa6ba3ebc2bc']);

var_dump($users);
/*
	result:
		array(
			[0] => array(
				'id' => 'c5420d81-499e-4c9c-ac0c-fa6ba3ebc2bc',
				'name' => 'userName',
				'email' => '[email protected]'
			)
		)
*/

// Keyspace can be changed at runtime
$database->setKeyspace('my_other_keyspace');
// Get from other keyspace
$urlsFromFacebook = $database->query('SELECT * FROM "urls" WHERE "host" = :host', ['host' => 'facebook.com']);

Using transaction

	$database->beginBatch();
	// all INSERT, UPDATE, DELETE query append into batch query stack for execution after applyBatch
	$uuid = $database->query('SELECT uuid() as "uuid" FROM system.schema_keyspaces LIMIT 1;')[0]['uuid'];
	$database->query(
			'INSERT INTO "users" ("id", "name", "email") VALUES (:id, :name, :email);',
			[
				'id' => $uuid,
				'name' => 'Mark',
				'email' => '[email protected]'
			]
		);

	$database->query(
			'DELETE FROM "users" WHERE "email" = :email;',
			[
				'email' => '[email protected]'
			]
		);
	$result = $database->applyBatch();

Supported datatypes

All types are supported.

  • ascii, varchar, text Result will be a string.
  • bigint, counter, varint Converted to strings using bcmath.
  • blob Result will be a string.
  • boolean Result will be a boolean as well.
  • decimal Converted to strings using bcmath.
  • double, float, int Result is using native PHP datatypes.
  • timestamp Converted to integer. Milliseconds precision is lost.
  • uuid, timeuuid, inet No native PHP datatype available. Converted to strings.
  • list, set Converted to array (numeric keys).
  • map Converted to keyed array.

php-cassandra-binary's People

Contributors

andreizet avatar evseevnn avatar larsfronius avatar locked avatar lstrz avatar marknotfound avatar michaltrmac avatar noonie2k avatar pascaln avatar salemuser avatar znarf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.