Package Data | |
---|---|
Maintainer Username: | irajtaghlidi |
Maintainer Contact: | yuuki.takezawa@comnect.jp.net (Yuuki Takezawa) |
Package Create Date: | 2018-08-13 |
Package Last Update: | 2018-08-13 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 15:11:20 |
Package Statistics | |
---|---|
Total Downloads: | 13 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
for Laravel 5.1.*(higher)
cache, session, database, queue extension package required ext-couchbase
Supported Auto-Discovery, Design Document, Cache Lock (Laravel5.5)
| Laravel version | Laravel-Couchbase version | ext-couchbase | | ------------- | ------------- | ------------------| | Laravel 5.6 | ^1.1 | >=2.3.2 | | Laravel 5.5 | ^1.0 | >=2.3.2 | | Laravel 5.4 | ^0.7 | ^2.2.2 | | Laravel 5.3 | ^0.6 | ^2.2.2 | | Laravel 5.2 | ^0.5 | ^2.2.2 | | Laravel 5.1 | ^0.4 | ^2.2.2 |
not recommended couchbase-memcached driver couchbase session driver
$ composer require ytake/laravel-couchbase
or your config/app.php
'providers' => [
// added service provider
\Ytake\LaravelCouchbase\CouchbaseServiceProvider::class,
\Ytake\LaravelCouchbase\ConsoleServiceProvider::class,
]
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
// 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();
$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',
]);
\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']
);
example)
"delete from testing USE KEYS "delete" RETURNING *"
"update testing USE KEYS "insert" set click = ? where click = ? RETURNING *"
default *
\DB::connection('couchbase')
->table('testing')
->where('id', 1)
->offset($from)->limit($perPage)
->orderBy('created_at', $sort)
->returning(['id', 'name'])->get();
$view = \DB::view("testing");
$result = $view->execute($view->from("dev_testing", "testing"));
config/cache.php
'couchbase' => [
'driver' => 'couchbase',
'bucket' => 'session'
],
'couchbase-memcached' => [
'driver' => 'couchbase-memcached',
'servers' => [
[
'host' => '127.0.0.1',
'port' => 11255,
'weight' => 100,
'bucket' => 'memcached-bucket-name',
'option' => [
// curl option
],
],
],
],
not supported
config/cache.php
'couchbase' => [
'driver' => 'couchbase',
'bucket' => 'session',
'bucket_password' => 'your bucket password'
],
.env etc..
specify couchbase driver
default :CouchbaseN1qlQuery::NOT_BOUNDED
$this->app['db']->connection('couchbase')
->consistency(\CouchbaseN1qlQuery::REQUEST_PLUS)
->table('testing')
->where('id', 1)
->returning(['id', 'name'])->get();
$this->app['db']->connection('couchbase')
->callableConsistency(\CouchbaseN1qlQuery::REQUEST_PLUS, function ($con) {
return $con->table('testing')->where('id', 1)->returning(['id', 'name'])->get();
});
for N1QL
| events | description | | ------------- | ------------- | | \Ytake\LaravelCouchbase\Events\QueryPrepared | get n1ql query | | \Ytake\LaravelCouchbase\Events\ResultReturning | get all property from returned result | | \Ytake\LaravelCouchbase\Events\ViewQuerying | for view query (request uri) |
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:
for couchbase manipulate indexes
| commands | description | | ------------- | ------------- | | couchbase:create-index | Create a secondary index for the current bucket. | | couchbase:create-primary-index | Create a primary N1QL index for the current bucket. | | couchbase:drop-index | Drop the given secondary index associated with the current bucket. | | couchbase:drop-primary-index | Drop the given primary index associated with the current bucket. | | couchbase:indexes | List all N1QL indexes that are registered for the current bucket. | | couchbase:create-queue-index | Create primary index, secondary indexes for the queue jobs couchbase bucket. | | couchbase:create-design | Inserts design document and fails if it is exist already. for MapReduce views |
-h
more information.
config/couchbase.php
return [
'design' => [
'Your Design Document Name' => [
'views' => [
'Your View Name' => [
'map' => file_get_contents(__DIR__ . '/../resources/sample.ddoc'),
],
],
],
]
];
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
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.
REST API / Creating and Editing Buckets
couchbase-cli / user-manage
Authentication
Authorization API