Skip to content

Commit

Permalink
Updated doc and api
Browse files Browse the repository at this point in the history
  • Loading branch information
belgattitude committed Dec 30, 2015
1 parent 8c00a25 commit 7ea5087
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 16 deletions.
50 changes: 41 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ To implement new sources for information schema (oracle, postgres...), just exte

## Examples

### Read MySQL information schema
### Retrieve table informations in a database schema

```php
<?php
Expand All @@ -69,20 +69,52 @@ $pdo = new PDO("mysql:host=$hostname", $username, $password, [

$schema = new Schema\Source\Mysql\MysqlInformationSchema($pdo);

// All schema configuration
$config = $schema->getSchemaConfig();
var_dump($config);
// Retrieve full information of all tables in schema
$info = $schema->getTablesInformation();

/*
Return an associative array index by table names.

Each table contains informations about
[
['table_name_1'] => [
['name'] => 'Table name'
['columns'] => 'Associative array with column names'
[
'col name_1' => ['name' => '', 'type' => '', ...]',
'col name_2' => ['name' => '', 'type' => '', ...]',
]

['primary_keys'] => 'Indexed array with primary column name(s)'
['unique_keys'] => 'Associative array with each unique indexes'
[
'index name_1' => ['col1', 'col2']',
'index_name_2' => ['col3']
]
['foreign_keys'] => 'Associative array with foreign keys specifications'
[
'col_1' => ['column' => '', 'referenced_column' => '', 'referenced_table' => ''],
'col_2' => ['column' => '', 'referenced_column' => '', 'referenced_table' => '']
]
['references'] => 'Associative array with relations from other tables'
[
'ref_table_1' => ['column' => '', 'referenced_column' => '', 'constraint_name' => ''],
'ref_table_2' => ['column' => '', 'referenced_column' => '', 'constraint_name' => ''],
]
['indexes'] => 'Associative array'
],
['table_name_2'] => [...]
]
*/

// Retrieve all tables names
$info = $schema->getTables();

// Test if table exists in schema
if ($schema->hasTable($table)) {
//...
}

//
// Full table information
$info = $schema->getTableInformation($table);


```

### Read table specific information
Expand Down
2 changes: 1 addition & 1 deletion src/Soluble/Schema/Source/Mysql/MysqlInformationSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected function getTableConfig($table, $include_options = false)
* @param boolean $include_options include extended information
* @return array
*/
public function getSchemaConfig($include_options = false)
protected function getSchemaConfig($include_options = false)
{
$schema = $this->schema;
if ($this->useLocalCaching && in_array($schema, self::$fullyCachedSchemas)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Soluble\Schema\Source\Mysql;

use Soluble\Schema\Db\Wrapper\MysqlConnectionAdapter;
use Reflection;

/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-03-04 at 16:46:00.
Expand Down Expand Up @@ -42,7 +43,14 @@ public function testGetSchemaConfigThrowsSchemaNotFoundException()
{
$this->setExpectedException('Soluble\Schema\Exception\SchemaNotFoundException');
$metadata = new MysqlInformationSchema($this->conn, $schema = "fdgdfgdfgppooaze");
$metadata->getSchemaConfig();

$method = new \ReflectionMethod('\Soluble\Schema\Source\Mysql\MysqlInformationSchema', 'getSchemaConfig');
$method->setAccessible(true);


$schema = $method->invoke($metadata);



}

Expand All @@ -65,18 +73,26 @@ public function testConstructThrowsInvalidArgumentException2()

public function testGetSchemaConfig()
{
$schema = $this->metadata->getSchemaConfig();

$method = new \ReflectionMethod('\Soluble\Schema\Source\Mysql\MysqlInformationSchema', 'getSchemaConfig');
$method->setAccessible(true);

$schema = $method->invoke($this->metadata);

$this->assertInternalType('array', $schema);
$this->assertInternalType('array', $schema['tables']);
$this->assertTrue(array_key_exists('product', $schema['tables']));
}

/*

public function testGetTableConfigThrowsTableNotFoundException()
{
$method = new \ReflectionMethod('\Soluble\Schema\Source\Mysql\MysqlInformationSchema', 'getTableConfig');
$method->setAccessible(true);

$this->setExpectedException('Soluble\Schema\Exception\TableNotFoundException');
$config = $this->metadata->getTableConfig('table_unexistent_999');
}*/
$method->invokeArgs($this->metadata, array('table_unexistent_999'));
$method->invoke($this->metadata);
}
/*
public function testGetTableConfig()
{
Expand Down Expand Up @@ -113,6 +129,8 @@ public function testGetRelations()
public function testGetTablesInformation()
{
$ti = $this->metadata->getTablesInformation();
var_dump($ti);
die();
$table = 'media';
$this->assertInternalType('array', $ti);
$this->assertArrayHasKey($table, $ti);
Expand Down

0 comments on commit 7ea5087

Please sign in to comment.