Skip to content

Commit

Permalink
Merge pull request #24 from linuxjuggler/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
duxet committed Feb 2, 2016
2 parents 3594bbf + 2cc7866 commit 2ccb658
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 5 deletions.
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,128 @@ RethinkDB adapter for Laravel (with Eloquent support)
God bless [@jenssegers](https://github.com/jenssegers) for his great [laravel-mongodb](https://github.com/jenssegers/laravel-mongodb) project. I have used his tests and some other code, since it's awesome codebase for supporting other NoSQL databases. I hope he won't be angry on me for that ;)

This project is aiming at Laravel 5 which is soon to be released, so it might not work with L4.

# Installation

## Requirements.

1. Rethinkdb : You need to make sure that you have installed [rethinkdb](http://www.rethinkdb.com) successfully, you can reffer to rethinkdb [documentation](https://rethinkdb.com/docs/) for the full instruction of how to install rethinkdb.

1. Laravel 5.2 : this package was designed to work with [laravel](http://laravel.com) 5.2, so it will not work with laravel 4.x.

## Installation

To fully install this package you will have either to add it manually to your `composer.json` file, or you can execute the following command :

`composer require "duxet/laravel-rethinkdb:dev-master"`

This will install the package and all the required package for it to work.

## Service Provider

After you install the library you will need to add the `Service Provider` file to your `app.php` file like :

`duxet\Rethinkdb\RethinkdbServiceProvider::class,`

inside your `providers` array.

## Database configuration

Now that you have the service provider setup, you will need to add the following configuration array at the end of your database connections array like :

'rethinkdb' => [
'name' => 'rethinkdb',
'driver' => 'rethinkdb',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 28015),
'database' => env('DB_DATABASE', 'homestead'),
]

After you add it, you can just configure your enviroment file to be something like :

DB_HOST=localhost
DB_DATABASE=homestead
DB_CONNECTION=rethinkdb

but you can always updatr 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`


## 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 duxet\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 \duxet\Rethinkdb\Eloquent\Model;

class News extends Model
{
//
}

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"illuminate/contracts": ">=5.0.0",
"illuminate/database": ">=5.0.0",
"illuminate/support": ">=5.0.0",
"danielmewes/php-rql": "~2.0.1"
"danielmewes/php-rql": "~2.2.0"
},
"require-dev": {
"psr/log": "1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

1. Rethinkdb : You need to make sure that you have installed [rethinkdb](http://www.rethinkdb.com) successfully, you can reffer to rethinkdb [documentation](https://rethinkdb.com/docs/) for the full instruction of how to install rethinkdb.

1. Laravel 5.1 : this package was designed to work with [laravel](http://laravel.com) 5.1, so it will not work with laravel 4.x.
1. Laravel 5.2 : this package was designed to work with [laravel](http://laravel.com) 5.2, so it will not work with laravel 4.x.

## Installation

Expand Down
4 changes: 2 additions & 2 deletions docs/migration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Migration

## Create a migration file
## 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:

Expand All @@ -9,7 +9,7 @@ You can easily create a migration file using the following command which will cr
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`


## Running the migrations
## 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.

Expand Down
24 changes: 24 additions & 0 deletions docs/model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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 \duxet\Rethinkdb\Eloquent\Model;

class News extends Model
{
//
}
80 changes: 80 additions & 0 deletions src/Console/Model/ModelMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace duxet\Rethinkdb\Console\Model;

use Illuminate\Foundation\Console\ModelMakeCommand as LaravelMakeModelCommand;
use Symfony\Component\Console\Input\InputOption;

class ModelMakeCommand extends LaravelMakeModelCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'make:rethink-model';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new Rethinkdb model class';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Model';

/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
if (parent::fire() !== false) {
if ($this->option('migration')) {
$table = Str::plural(Str::snake(class_basename($this->argument('name'))));

$this->call('make:rethink-migration', ['name' => "create_{$table}_table", '--create' => $table]);
}
}
}

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__.'/stubs/model.stub';
}

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
*
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace;
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['migration', 'm', InputOption::VALUE_NONE, 'Create a new migration file for the model.'],
];
}
}
10 changes: 10 additions & 0 deletions src/Console/Model/stubs/model.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace DummyNamespace;

use \duxet\Rethinkdb\Eloquent\Model;

class DummyClass extends Model
{
//
}
9 changes: 8 additions & 1 deletion src/RethinkdbServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace duxet\Rethinkdb;

use duxet\Rethinkdb\Console\Migrations\MigrateMakeCommand;
use duxet\Rethinkdb\Console\Model\ModelMakeCommand;
use duxet\Rethinkdb\Eloquent\Model;
use duxet\Rethinkdb\Migrations\MigrationCreator;
use Illuminate\Support\ServiceProvider;
Expand Down Expand Up @@ -42,10 +43,16 @@ public function register()
});

$this->commands('command.rethink-migrate.make');

$this->app->singleton('command.rethink-model.make', function ($app) {
return new ModelMakeCommand($app['files']);
});

$this->commands('command.rethink-model.make');
}

public function provides()
{
return ['command.rethink-migrate.make'];
return ['command.rethink-migrate.make', 'command.rethink-model.make'];
}
}

0 comments on commit 2ccb658

Please sign in to comment.