dooaki / phroonga
PHP 的 Groonga
dev-master
2014-09-03 03:25 UTC
Requires
- php: >=5.5.0
- dooaki/container: @dev
- guzzle/guzzle: 3.9.*
Requires (Dev)
- phpunit/phpunit: 4.2.*
- satooshi/php-coveralls: @dev
This package is not auto-updated.
Last update: 2024-09-24 04:04:44 UTC
README
Groonga 的 PHP 客户端
命名空间
dooaki\Phroonga
要求
php 5.5.0 或更高版本
安装
编写 composer.json 并运行 composer install。
{ "require": { "dooaki/phroonga": "dev-master" } }
用法
使用 GroongaEntity trait 的类可以作为实体来管理 Groonga 的一个表。
表的定义是通过 _schema 这个静态方法来完成的,使用 self::Table, self::Column 等进行定义。
use dooaki\Phroonga\Groonga; use dooaki\Phroonga\GroongaEntity; class User { use GroongaEntity; public static function _schema() { self::Table( 'Users', [ 'flags' => 'TABLE_HASH_KEY', 'key_type' => 'ShortText' ] ); self::Column('age', 'Int32'); } } $grn = new Groonga('https://:10043'); $grn->activate(); // associate GroongaEntity and Groonga $grn->create(); // table_create and column_create $u1 = new User(); $u1->_key = 'alice'; $u1->age = 18; $u1->save(); // load $u2 = new User(); $u2->_key = 'bob'; $u2->age = 20; $u2->save(); // load $alice = User::select()->find('alice'); // select echo "{$alice->_key} is {$alice->age} years old.", PHP_EOL;
上述代码与在 Groonga 的控制台中执行以下命令的效果相同
> table_create --name User --flags TABLE_HASH_KEY --key_type ShortText
> column_create --table User --name age --type Int32
> load --table User
[{"_key":"alice","age":18},{"_key":"bob","age":20}]
> select --table User --query "_key:alice"