pin-cnx/orientdb-laravel-5

Laravel Orientdb 驱动程序

dev-master 2016-03-08 13:37 UTC

This package is auto-updated.

Last update: 2024-09-18 00:58:21 UTC


README

Orientdb 图形 Eloquent 驱动程序,适用于 Laravel 5

快速参考

需求

  • Laravel 5.1 或更高版本
  • Orientdb 服务器 2.1 或更高版本

安装

将包添加到您的 composer.json 文件中,并运行 composer update

{
    "require": {
        "sgpatil/orientdb-laravel-5": "dev-master"
    }
}

config/app.php 中添加服务提供者

Sgpatil\Orientdb\OrientdbServiceProvider::class,

这将注册此包所需的所有类。

数据库配置

打开 config/database.php,将 orientdb 设置为默认连接

'default' => 'orientdb',
'default_nosql' => 'orientdb', //optional if you are using orientdb as a secondary connection

添加连接默认值

'connections' => [
    'orientdb' => [
        'driver' => 'orientdb',
        'host'   => 'localhost',
        'port'   => '2480',
        'database' => 'database_name',
        'username' => 'root',
        'password' => 'root'
    ]
]

在 'username' 和 'password' 字段中添加您的数据库用户名和密码。在 'database_name' 中添加您想要连接和使用的 Orientdb 数据库名称。

迁移

要创建迁移,您可以在 Artisan CLI 上使用 orient 命令

php artisan orient:make create_users_table

迁移将放置在您的数据库/migrations 文件夹中,并包含一个时间戳,以便框架确定迁移的顺序。

也可以使用 --table 和 --create 选项来指定表名,以及迁移是否会创建新表

php artisan orient:make add_votes_to_users_table --table=users_votes

php artisan orient:make create_users_table --create=users

运行迁移

php artisan orient:migrate

使用方法

// To insert a record
class User extends \Orientdb {

    protected $fillable = ['name', 'email'];
}

$user = User::create(['name' => 'Some Name', 'email' => 'some@email.com']);

您可以通过扩展 Orientdb 到模型类来使用它。

获取所有记录

$users = User::all();
foreach($users as $user){
        echo $user->id;
        echo $user->name;
        echo $user->email;
    }

查找记录

$user = User::find(1);

更新记录

$user = User::find(1);
$user->name = "New Name";
$user->save();

关系

创建一对一关系

$user =   User::create(['name'=>"Sumit", 'email' => "demo@email.com"]); // Create User node
$phone = new Phone(['code' => 963, 'number' => '98555533']); // Create Phone node
$relation = $user->has_phone()->save($phone); // Creating relationship

找不到 has_phone() 方法?查看完整示例。

想了解更多?查看维基百科。