irajtaghlidi / laravel-couchbase
Couchbase providers for Laravel
Requires
- php: ^7.1.3
- ext-couchbase: >=2.3.2
- illuminate/cache: 5.6.*
- illuminate/config: 5.6.*
- illuminate/console: 5.6.*
- illuminate/container: 5.6.*
- illuminate/contracts: 5.6.*
- illuminate/database: 5.6.*
- illuminate/encryption: 5.6.*
- illuminate/events: 5.6.*
- illuminate/queue: 5.6.*
- illuminate/session: 5.6.*
- illuminate/support: 5.6.*
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- pdepend/pdepend: ^2.2.4
- phploc/phploc: *
- phpmd/phpmd: @stable
- phpunit/phpunit: ^6.0
- satooshi/php-coveralls: *
- symfony/console: ^4.0
- symfony/framework-bundle: ^4.0
- dev-master
- 1.1.0
- 1.0.1
- 1.0.0
- 0.7.1
- 0.6.7
- 0.6.6
- 0.6.5
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.3
- 0.5.2
- 0.5.1
- 0.4.7
- 0.4.6
- 0.4.5
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2-beta
- 0.1.1-beta
- 0.1-beta
- dev-master-5.5
- dev-master-5.3
- dev-master-5.2
- dev-master-5.1
- dev-master-5.4
- dev-master-0.3
- dev-master-laravel4
This package is not auto-updated.
Last update: 2024-12-22 07:33:31 UTC
README
for Laravel 5.1.*(higher)
cache, session, database, queue extension package required ext-couchbase
Notice
Supported Auto-Discovery, Design Document, Cache Lock (Laravel5.5)
Deprecated
not recommended couchbase-memcached driver couchbase session driver
install
$ composer require ytake/laravel-couchbase
or your config/app.php
'providers' => [ // added service provider \Ytake\LaravelCouchbase\CouchbaseServiceProvider::class, \Ytake\LaravelCouchbase\ConsoleServiceProvider::class, ]
usage
database extension
add database driver(config/database.php)
'couchbase' => [ 'driver' => 'couchbase', 'host' => 'couchbase://127.0.0.1', 'user' => 'userName', // optional administrator 'password' => 'password', // optional administrator // optional configuration / management operations against a bucket. 'administrator' => [ 'user' => 'Administrator', 'password' => 'password', ], ],
case cluster
'couchbase' => [ 'driver' => 'couchbase', 'host' => 'couchbase://127.0.0.1,192.168.1.2', 'user' => 'userName', // optional administrator 'password' => 'password', // optional administrator ],
choose bucket table()
method
or
basic usage bucket()
method
N1QL supported(upsert enabled)
see http://developer.couchbase.com/documentation/server/4.1/n1ql/n1ql-language-reference/index.html
SELECT
// service container access $this->app['db']->connection('couchbase') ->table('testing')->where('whereKey', 'value')->first(); // use DB facades \DB::connection('couchbase') ->table('testing')->where('whereKey', 'value')->get();
INSERT / UPSERT
$value = [ 'click' => 'to edit', 'content' => 'testing' ]; $key = 'insert:and:delete'; $result = \DB::connection('couchbase') ->table('testing')->key($key)->insert($value); \DB::connection('couchbase') ->table('testing')->key($key)->upsert([ 'click' => 'to edit', 'content' => 'testing for upsert', ]);
DELETE / UPDATE
\DB::connection('couchbase') ->table('testing')->key($key)->where('clicking', 'to edit')->delete(); \DB::connection('couchbase') ->table('testing')->key($key) ->where('click', 'to edit')->update( ['click' => 'testing edit'] );
execute queries
example)
"delete from testing USE KEYS "delete" RETURNING *" "update testing USE KEYS "insert" set click = ? where click = ? RETURNING *"
returning
default *
\DB::connection('couchbase') ->table('testing') ->where('id', 1) ->offset($from)->limit($perPage) ->orderBy('created_at', $sort) ->returning(['id', 'name'])->get();
View Query
$view = \DB::view("testing"); $result = $view->execute($view->from("dev_testing", "testing"));
cache extension
for bucket type couchbase
config/cache.php
'couchbase' => [ 'driver' => 'couchbase', 'bucket' => 'session' ],
for bucket type memcached
'couchbase-memcached' => [ 'driver' => 'couchbase-memcached', 'servers' => [ [ 'host' => '127.0.0.1', 'port' => 11255, 'weight' => 100, 'bucket' => 'memcached-bucket-name', 'option' => [ // curl option ], ], ], ],
not supported
couchbase bucket, use bucket password
config/cache.php
'couchbase' => [ 'driver' => 'couchbase', 'bucket' => 'session', 'bucket_password' => 'your bucket password' ],
session extension
.env etc..
specify couchbase driver
consistency
default :CouchbaseN1qlQuery::NOT_BOUNDED
$this->app['db']->connection('couchbase') ->consistency(\CouchbaseN1qlQuery::REQUEST_PLUS) ->table('testing') ->where('id', 1) ->returning(['id', 'name'])->get();
callable consistency
$this->app['db']->connection('couchbase') ->callableConsistency(\CouchbaseN1qlQuery::REQUEST_PLUS, function ($con) { return $con->table('testing')->where('id', 1)->returning(['id', 'name'])->get(); });
Event
for N1QL
Schema / Migrations
The database driver also has (limited) schema builder support.
easily manipulate indexes(primary and secondary)
use Ytake\LaravelCouchbase\Schema\Blueprint as CouchbaseBlueprint; \Schema::create('samples', function (CouchbaseBlueprint $table) { $table->primaryIndex(); // primary index $table->index(['message', 'identifier'], 'sample_secondary_index'); // secondary index // dropped $table->dropIndex('sample_secondary_index'); $table->dropPrimary(); });
Supported operations:
- create and drop
- index and dropIndex (primary index and secondary index)
Artisan
for couchbase manipulate indexes
-h
more information.
create design
config/couchbase.php
return [ 'design' => [ 'Your Design Document Name' => [ 'views' => [ 'Your View Name' => [ 'map' => file_get_contents(__DIR__ . '/../resources/sample.ddoc'), ], ], ], ] ];
Queue
Change the the driver in config/queue.php:
'connections' => [ 'couchbase' => [ 'driver' => 'couchbase', 'bucket' => 'jobs', 'queue' => 'default', 'retry_after' => 90, ], ],
example
php artisan queue:work couchbase --queue=send_email
hacking
To run tests there are should be following buckets created on local Couchbase cluster:
$cluster = new CouchbaseCluster('couchbase://127.0.0.1'); $clusterManager = $cluster->manager('Administrator', 'password'); $clusterManager->createBucket('testing', ['bucketType' => 'couchbase', 'saslPassword' => '', 'flushEnabled' => true]); $clusterManager->createBucket('memcache-couch', ['bucketType' => 'memcached', 'saslPassword' => '', 'flushEnabled' => true]); sleep(5); $bucketManager = $cluster->openBucket('testing')->manager(); $bucketManager->createN1qlPrimaryIndex();
Also tests are expecting regular Memcached daemon listening on port 11255.
soon
- authintication driver
- Eloquent support
Couchbase Document
REST API / Creating and Editing Buckets
couchbase-cli / user-manage
Authentication
Authorization API