robclancy/schema-builder

There is no license information available for the latest version (dev-master) of this package.

Fork of illuminate/database to use the schema builder alone.

dev-master / 1.0.x-dev 2013-04-13 03:23 UTC

This package is auto-updated.

Last update: 2024-11-22 04:37:00 UTC


README

This is a port of http://github.com/illuminate/database to provide the schema builder without all the extra features.

Build Status

The idea behind this is allowing the scheme builder to be used in projects that already have a database layer that uses PDO.

All you need to use this is a PDO instance. If you create it manually you might want to consider using http://github.com/robclancy/db-connector which is another fork of http://github.com/illuminate/database but to just connect to the database. With your PDO instance you create a Robbo\SchemaBuilder\Connection instance and then call ->getSchemaBuilder() to get started. Then you use the builder as described in the [http://four.laravel.com/docs/schema](Laravel docs) however substitute your instance for Schema::.

Installation

Add the following to the "require" section of your composer.json file:

	"robclancy/schema-builder": "1.0.x"

Native example

Following example will assume you have a PDO instance stored in $pdo.

// Create the connection
$connection = new Robbo\SchemaBuilder\Connection\MySqlConnection($pdo, 'database_name', 'tableprefix_');

// Alternatively you can use a factory method to create an instance depending on the driver
// Drivers supported: mysql, pgsql, sqlite and sqlsrv
$connection = Robbo\SchemaBuilder\Connection::create('mysql', $pdo, 'database_name', 'tableprefix_')

$builder = $connection->getSchemaBuilder();

// Now you can use it like in the laravel docs...
$builder->create('users', function($table)
{
    $table->increments('id');
});

Support for a dry run is also supported using the functionality from illuminate/database. Use it like so...

// $builder and $connection is the same from above

$queries = $connection->pretend(function($connection) use ($builder)
{
	// Could use $connection->getSchemaBuilder() here in place of $builder
	$builder->create('users', function($table)
	{
	    $table->increments('id');
	});
});

// Now $queries will contain all queries that were created