shen2/fluent-cql
Composer 安装命令:
composer require shen2/fluent-cql
包简介
an php CQL building library
关键字:
README 文档
README
Dependency
- PHP 5.4+
- duoshuo/php-cassandra (Required)
- duoshuo/uuid (Optional)
Initialize
$connection = new Cassandra\Connection(['127.0.0.1'], 'my_keyspace');
FluentCQL\Query
- SELECT COMMAND
$query = FluentCQL\Query::select('count(*)') ->from('table_name') ->where('id = ?', 123); $query->assemble(); // SELECT count(*) FROM table_name where id = 123 $query->setDbAdapter($connection)->querySync(); // execute query syncronously
- INSERT COMMAND
$query = FluentCQL\Query::insertInto('table_name') ->clause('(from_id, to_id, updated_uuid)') ->values('(?, ?, ?)', 321, 123, new \Cassandra\Type\Timeuuid('2dc65ebe-300b-11e4-a23b-ab416c39d509')); $query->assemble(); // INSERT INTO table_name (from_id, to_id, updated_uuid) values (321, 123, 2dc65ebe-300b-11e4-a23b-ab416c39d509); $query->setDbAdapter($connection)->querySync(); // execute query syncronously
- UPDATE COMMAND
$query = FluentCQL\Query::update('table_name') ->set('a = :a, b = :b', $a, $b) ->where('c = :c', $c) ->and('d = :d', $d) ->ifExists(); $query->assemble(); // 'UPDATE table_name SET a = :a, b = :b WHERE c = :c AND d = :d' $query->setDbAdapter($connection)->querySync(); // execute query syncronously
- DELETE COMMAND
$query = FluentCQL\Query::delete() ->from('table_name') ->where('id = ?', 123); $query->assemble(); // DELETE FROM table_name where id = 123 $query->setDbAdapter($connection)->querySync(); // execute query syncronously
FluentCQL\Table
Table Class Definition
class Friendship extends \FluentCQL\Table{ protected static $_name = 'friendship'; protected static $_primary = array('from_id', 'to_id'); protected static $_columns = array( 'from_id' => Type\Base::BIGINT, 'to_id' => Type\Base::BIGINT, 'updated_uuid' => Type\Base::TIMEUUID, ); protected static $_readConsistency = 0x0001; protected static $_writeConsistency = 0x0002; }
Initialize
$connection = new Cassandra\Connection(['127.0.0.1'], 'my_keyspace'); FluentCQL\Table::setDefaultDbAdapter($connection);
Queries
- Table::find()
$response = Friendship::find(321, 123); // synchronously query and get binary response $response->fetchAll(); // get all rows in a SplFixedArray $response->fetchRow(); // get first row in a ArrayObject from response
- Table::select()
// this way totally equal to Friendship::find() $response = Friendship::select() ->where('from_id = ? AND to_id = ?', 321, 123) ->querySync();
- Table::insert()
$response = Friendship::insert() ->clause('(from_id, to_id, updated_uuid)') ->values('(?, ?, ?)', 321, 123, new \Cassandra\Type\Timeuuid('2dc65ebe-300b-11e4-a23b-ab416c39d509')) ->querySync();
- Table::update()
$response = Friendship::update() ->set('update_uuid = ?', new \Cassandra\Type\Timeuuid('2dc65ebe-300b-11e4-a23b-ab416c39d509')) ->where('from_id = ? AND to_id = ?', 321, 123) ->querySync();
- Table::delete()
$response = Friendship::delete() ->where('from_id = ? AND to_id = ?', 321, 123) ->if('updated_uuid = ?', new \Cassandra\Type\Timeuuid('2dc65ebe-300b-11e4-a23b-ab416c39d509')) ->querySync();
- Table::insertRow($data)
// Insert a row through an array. $response = Friendship::insertRow([ 'from_id' => 123, 'to_id' => 321, 'updated_uuid'=> '2dc65ebe-300b-11e4-a23b-ab416c39d509', ])->querySync();
- Table::updateRow($primary, $data)
// Update a row by primary key. $response = Friendship::updateRow([123, 321], ['updated_uuid'=> '2dc65ebe-300b-11e4-a23b-ab416c39d509'])->querySync();
- Table::deleteRow($primary)
// Delete a row or rows by primary key. $response = Friendship::deleteRow([123])->querySync();
Custom Consistency and Options
$query = new FluentCQL\Query(); $query->setConsistency(0x0001) ->setOptions(['page_size' => 20]);
ActiveRecord-like Usage
$post = new Friendship(); $post['from_id'] = 123; $post['to_id'] = 321; $post['updated_uuid'] = '2dc65ebe-300b-11e4-a23b-ab416c39d509'; $post->save();
shen2/fluent-cql 适用场景与选型建议
shen2/fluent-cql 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.51k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2014 年 09 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nosql」 「orm」 「cassandra」 「cql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shen2/fluent-cql 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shen2/fluent-cql 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shen2/fluent-cql 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The Cassandra php driver library IDE stubs which enables autocompletion in modern IDEs.
Cassandra Thrift Wrapper
The DreamFactory(tm) CouchDB Service.
Kinikit - PHP Application development framework MVC component
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
The CodeIgniter Redis package
统计信息
- 总下载量: 8.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-09-05