egretos / orio
Orio is a good OrientDB query builder based on the PHPOrient.
dev-master
2018-12-17 15:32 UTC
Requires
- php: >=7.0
- ostico/phporient: >=1.2.5
- psr/log: ~1.0
This package is auto-updated.
Last update: 2025-03-10 19:05:29 UTC
README
Orio is a simple OrientDB query builder based on the PHPOrient.
Tested on Orientdb version 2.1.3
Requires
- PHP Version >= 5.4 ( Socket extension enabled )
- phporient by ostico
Installation
Using git:
git clone https://github.com/egretos/orio.git
Using composer
Install composer
php -r "readfile('https://getcomposer.org/installer');" | php php composer.phar --no-dev install
Install Orio
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
$result = DB::command("select from #12:0");
Select by class
Return array of Orio Model
$result = DB::select('User')->get();
Getting with custom fields
By default get() return all fields
$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
$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:
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:
$result = DB::byRid('#12:0');
or use select()->one()
$result = DB::select('#12:0')->one();
Getting linked Records
The result will be Dmitry's friends.
$result = DB::select('User') ->where('name', 'Dmitry') ->linked('Friend') ->get();
The result will be all members of the group "Developers"
$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".
$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".
$result = DB::select('Group') ->where('name', 'Developers') ->linked('Member') ->where('name', 'Dmitry') ->linked('Friend') ->linked('Likes', 'in') ->get();
License
MIT