lithium\data\source\http\adapter\CouchDb::describe PHP Method

describe() public method

Describe database, create if it does not exist.
public describe ( string $entity, array $schema = [], array $meta = [] ) : lithium\data\Schema
$entity string
$schema array Any schema data pre-defined by the model.
$meta array
return lithium\data\Schema
    public function describe($entity, $schema = array(), array $meta = array())
    {
        $database = $this->_config['database'];
        if (!$this->_db) {
            $result = $this->get($database);
            if (isset($result->db_name)) {
                $this->_db = true;
            }
            if (!$this->_db) {
                if (isset($result->error)) {
                    if ($result->error === 'not_found') {
                        $result = $this->put($database);
                    }
                }
                if (isset($result->ok) || isset($result->db_name)) {
                    $this->_db = true;
                }
            }
        }
        if (!$this->_db) {
            throw new ConfigException("Database `{$entity}` is not available.");
        }
        return $this->_instance('schema', array(array('fields' => $schema)));
    }

Usage Example

示例#1
0
 public function testDescribe()
 {
     $couchdb = new CouchDb($this->_testConfig);
     $this->expectException('/companies is not available/');
     $result = $couchdb->describe('companies');
     $this->assertNull($result);
 }
All Usage Examples Of lithium\data\source\http\adapter\CouchDb::describe