phillx/lumen-rethinkdb
Composer 安装命令:
composer require phillx/lumen-rethinkdb
包简介
RethinkDB adapter for Lumen
README 文档
README
This package is fork of duxet/laravel-rethinkdb with fix and how-to for Lumen 5.6
Installation
Requirements.
-
Rethinkdb : You need to make sure that you have installed rethinkdb successfully, you can reffer to rethinkdb documentation for the full instruction of how to install rethinkdb.
-
Lumen 5.6
Installation
Composer command to install:
composer require "phillx/lumen-rethinkdb:dev-master"
This will install the package and all other required packages needed to work.
Service Provider
After you install the library you will need to register the Service Provider file in your bootstrap/app.php file like :
$app->register(Phillx\Rethinkdb\RethinkdbServiceProvider::class);
$app->withEloquent();
Database configuration
Now you need to create file config/database.php with content like:
<?php
return [
'default' => 'rethinkdb',
'connections' => [
'rethinkdb' => [
'name' => 'rethinkdb',
'driver' => 'rethinkdb',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 28015),
'database' => env('DB_DATABASE', 'homestead'),
]
],
'migrations' => 'migrations',
];
After you create it, you can just edit your .env file:
DB_HOST=localhost
DB_DATABASE=rethinkdb_name
DB_CONNECTION=rethinkdb
but you can always update your DB_HOST to point to the IP where you have installed rethinkdb.
Migration
Create a Migration File
You can easily create a migration file using the following command which will create a migration file for you to create the users table and use the package schema instead of Laravel schema:
php artisan make:rethink-migration Users --create
Please note that you can use the same options that you use in make:migration with make:rethink-migration, as its based on laravel make:migration
Be aware that Laravel Schema API is not fully implemented. For example, ID columns using increments will not be auto-incremented unsigned integers, and will instead be a UUID unless explicitly set. The easiest solution is to maintain UUID use within RethinkDB, turn off incremental IDs in Laravel, and finally implement UUID use in Laravel.
Running The Migrations
Nothing will change here, you will keep using the same laravel commands which you are used to execute to run the migration.
Example of Laravel Users Migration file
This is an example of how the laravel Users Migration file has become
<?php
use Phillx\Rethinkdb\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
Model
Create a Model Class
You can easily create a model class using the following command which will create it for you and use the package model instead of Laravel model:
php artisan make:rethink-model News
Please note that you can use the same options that you use in make:model with make:rethink-model, as its based on laravel make:model
Example of Laravel News Model Class
This is an example of how the laravel model class has become
<?php
namespace App;
use \Phillx\Rethinkdb\Eloquent\Model;
class News extends Model
{
//
}
Update a Model Class
Be aware that any model that Laravel generates during its initial installation will need to be updated manually in order for them to work properly. For example, the User model extends Illuminate\Foundation\Auth\User, which further extends Illuminate\Database\Eloquent\Model instead of \duxet\Rethinkdb\Eloquent\Model;. The import Illuminate\Foundation\Auth\User needs to be removed from the User model and replaced with \duxet\Rethinkdb\Eloquent\Model;, and any interfaces and associated traits implemented in Illuminate\Foundation\Auth\User that are required will need to be ported to the User model.
Example of Laravel User Model Class
This is an example of how the laravel User model class has become
use Illuminate\Auth\Authenticatable;
use \Phillx\Rethinkdb\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements
AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
//
}
phillx/lumen-rethinkdb 适用场景与选型建议
phillx/lumen-rethinkdb 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 03 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 phillx/lumen-rethinkdb 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phillx/lumen-rethinkdb 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-12