Skip to content

Returns column information from database tables.

License

Notifications You must be signed in to change notification settings

rougin/describe

Repository files navigation

Describe

Latest Version on Packagist Software License Build Status Coverage Status Total Downloads

Describe is a PHP package that returns details of each column based on the database table schema.

Installation

Install Describe via Composer:

$ composer require rougin/describe

Basic Usage

Using a vendor-specific driver

use Rougin\Describe\Driver\MysqlDriver;

$dsn = 'mysql:host=localhost;dbname=test';

$pdo = new PDO($dsn, 'root', '');

$driver = new MysqlDriver($pdo, 'test');

Available drivers:

Using a DatabaseDriver

use Rougin\Describe\Driver\DatabaseDriver;

$creds = array('password' => '');

$creds['hostname'] = 'localhost';
$creds['database'] = 'test';
$creds['username'] = 'root';

$driver = new DatabaseDriver('mysql', $creds);

Using Table

use Rougin\Describe\Table;

$table = new Table('users', $driver);

// Returns a list of columns
var_dump($table->columns());

// Returns the primary key "Column" from the table
var_dump($table->primary());

For more information regarding the Column object, kindly check it here.

Adding a new database driver

To add a driver for a specified database, just implement it to a DriverInterface:

namespace Rougin\Describe\Driver;

interface DriverInterface
{
    /**
     * Returns a list of columns from a table.
     *
     * @param  string $table
     * @return \Rougin\Describe\Column[]
     */
    public function columns($table);

    /**
     * Returns a list of tables.
     *
     * @return \Rougin\Describe\Table[]
     */
    public function tables();
}

Projects using Describe

Combustor uses Describe for getting database information for generating a codebase.

Same as Combustor, Refinery also uses Describe for creating database migrations for Codeigniter.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Credits

License

The MIT License (MIT). Please see LICENSE for more information.