Пример #1
0
 public function testShouldReturnTrue()
 {
     $clusterManager = $this->createBucket("sample1");
     $schemaBuilder = $this->connection->getSchemaBuilder();
     $this->assertTrue($schemaBuilder->hasColumn("sample1", "testing"));
     $this->assertTrue($schemaBuilder->hasColumns("sample1", ["testing"]));
     $this->removeBucket($clusterManager, "sample1");
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function hasTable($table)
 {
     try {
         if (!is_null($this->connection->openBucket($table)->getName())) {
             return true;
         }
     } catch (\CouchbaseException $e) {
         return false;
     }
 }
Пример #3
0
 /**
  * @see \Ytake\LaravelCouchbase\Query\View::from()
  * @see \Ytake\LaravelCouchbase\Query\View::execute()
  */
 public function testItShouldBeStdClass()
 {
     /** @var Illuminate\Events\Dispatcher $dispatcher */
     $dispatcher = $this->app['events'];
     $dispatcher->listen(\Ytake\LaravelCouchbase\Events\ViewQuerying::class, function ($instance) {
         $this->assertInstanceOf(\Ytake\LaravelCouchbase\Events\ViewQuerying::class, $instance);
         $this->assertNotNull($instance->path);
     });
     $view = $this->connection->view("testing");
     $query = $view->from("dev_testing", "testing");
     $result = $view->execute($query);
     $this->assertInstanceOf('stdClass', $result);
 }
Пример #4
0
 public function testBlueprintSchemaBuildAndDropIndexes()
 {
     $schema = $this->connection->getSchemaBuilder();
     $schema->create('sample', function (\Ytake\LaravelCouchbase\Schema\Blueprint $blueprint) {
         $blueprint->primaryIndex();
         $blueprint->index(["message"], "secondary");
         $blueprint->dropPrimary();
         $blueprint->dropIndex("secondary");
     });
     $indexes = $this->connection->openBucket('sample')->manager()->listN1qlIndexes();
     foreach ($indexes as $index) {
         $this->assertNotSame('sample', $index->keyspace);
     }
     $this->removeBucket($this->connection->manager(), 'sample');
     sleep(5);
 }
Пример #5
0
 /**
  * supported N1QL upsert query.
  *
  * @param array $values
  *
  * @return bool|mixed
  */
 public function upsert(array $values)
 {
     if (empty($values)) {
         return true;
     }
     $values = $this->detectValues($values);
     $bindings = [];
     foreach ($values as $record) {
         foreach ($record as $key => $value) {
             $bindings[$key] = $value;
         }
     }
     $sql = $this->grammar->compileUpsert($this, $values);
     return $this->connection->upsert($sql, $bindings);
 }
Пример #6
0
 /**
  * generate increment key
  *
  * @param int $initial
  *
  * @return int
  */
 protected function incrementKey($initial = 1)
 {
     $result = $this->database->openBucket($this->table)->counter($this->identifier(), $initial, ['initial' => abs($initial)]);
     return $result->value;
 }
Пример #7
0
 /**
  * Specify a secondary index for the current bucket.
  *
  * @param array   $columns            the JSON fields to index.
  * @param string  $name               the name of the index.
  * @param string  $whereClause        the WHERE clause of the index.
  * @param boolean $ignoreIfExist      if a secondary index already exists with that name, an exception will be
  *                                    thrown unless this is set to true.
  * @param boolean $defer              true to defer building of the index until buildN1qlDeferredIndexes() is
  *                                    called (or a direct call to the corresponding query service API).
  *
  * @return mixed
  */
 public function index($columns, $name = null, $whereClause = '', $ignoreIfExist = false, $defer = false)
 {
     $name = is_null($name) ? $this->getTable() . "_secondary_index" : $name;
     return $this->connection->openBucket($this->getTable())->manager()->createN1qlIndex($name, $columns, $whereClause, $ignoreIfExist, $defer);
 }