Orio v1.1.0
Orio is a simple OrientDB query builder based on the PHPOrient., (*1)
Tested on Orientdb version 2.1.3, (*2)
Requires
Installation
Using git:
git clone https://github.com/egretos/orio.git
Using composer
Install composer, (*3)
php -r "readfile('https://getcomposer.org/installer');" | php
php composer.phar --no-dev install
Install Orio, (*4)
php composer.phar require "egretos/orio:dev-master" --update-no-dev
Usage
require "vendor/autoload.php";
use Orio\DB;
Connecting to server
$DBconfig = [
'hostname' => '127.0.0.1',
'port' => 2424,
'username' => 'username',
'password' => 'password',
'name' => 'DB name',
];
DB::init($DBConfig);
Simple query
Return array of phporient Records, (*5)
$result = DB::command("select from #12:0");
Select by class
Return array of Orio Model, (*6)
$result = DB::select('User')->get();
Getting with custom fields
By default get() return all fields, (*7)
$result = DB::select('User')
->get('name'); //one field
$result = DB::select('User')
->get(['name', 'email']); //many fields
Getting by condition
Return array of Orio Model, (*8)
$result = DB::select('User')
->where('name', 'Joe')
->get();
$result = DB::select('User')
->where('age', '>', '18')
->get();
Getting one record by rid
Return Orio Model. Usage:, (*9)
use PhpOrient\Protocols\Binary\Data\ID
// 3 variants of definition
$rid = new ID( '#12:0' );
$rid = new ID( 12, 0 );
$rid = new ID( [ 'cluster' => 12, 'position' => 0 ] );
// getting model
$result = DB::byRid($rid);
You can write easier:, (*10)
$result = DB::byRid('#12:0');
or use select()->one(), (*11)
$result = DB::select('#12:0')->one();
Getting linked Records
The result will be Dmitry's friends., (*12)
$result = DB::select('User')
->where('name', 'Dmitry')
->linked('Friend')
->get();
The result will be all members of the group "Developers", (*13)
$result = DB::select('Group')
->where('name', 'Developers')
->linked('Member')
->get();
The result will be friends of Dmitry, who is a member of the group of "Developers"., (*14)
$result = DB::select('Group')
->where('name', 'Developers')
->linked('Member')
->where('name', 'Dmitry')
->linked('Friend')
->get();
The result will be all users, who likes Dmitry`s friends, who is a member of the group of "Developers"., (*15)
$result = DB::select('Group')
->where('name', 'Developers')
->linked('Member')
->where('name', 'Dmitry')
->linked('Friend')
->linked('Likes', 'in')
->get();
License
MIT, (*16)