rougin/describe

Returns an array of column information from a database table.

v1.7.0 2018-01-09 16:17 UTC

README

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

Describe is a PHP library that returns Column objects based on table schema information from a database.

Installation

Install Describe through Composer:

$ composer require rougin/describe

Basic Usage

Using a vendor-specific driver

use Rougin\Describe\Driver\MySQLDriver;

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

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

$driver = new MySQLDriver($pdo, 'demo');

Available drivers:

Using a DatabaseDriver

use Rougin\Describe\Driver\DatabaseDriver;

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

$credentials['hostname'] = 'localhost';
$credentials['database'] = 'demo';
$credentials['username'] = 'root';

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

Using Table

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

// Returns an array of "Column" instances
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;

/**
 * Database Driver Interface
 *
 * An interface for handling PDO drivers.
 *
 * @package Describe
 * @author  Rougin Royce Gutib <rougingutib@gmail.com>
 */
interface DriverInterface
{
    /**
     * Returns an array of Column instances from a table.
     *
     * @param  string $table
     * @return \Rougin\Describe\Column[]
     */
    public function columns($table);

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

Projects using Describe

Combustor

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

Refinery

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

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email rougingutib@gmail.com instead of using the issue tracker.

Credits

License

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