litek/tabler

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

dev-master 2012-09-25 18:15 UTC

This package is not auto-updated.

Last update: 2024-05-25 11:54:08 UTC


README

Simple table data gateway built on Doctrine DBAL.

$connection = Doctrine\DBAL\DriverManager::getConnection(array(
  'pdo' => new \PDO('sqlite::memory:'),
  'wrapperClass' => 'Tabler\\Connection',
  'namespace' => 'App'
));

# SELECT * FROM users WHERE id = 1
$connection->find('users', ['id' => 1]);

# SELECT id, name FROM users WHERE id = 1
$connection->find('users', ['id', 'name'], ['id' => 1]);

# SELECT * FROM users
$connection->findAll('users');

# SELECT * FROM users WHERE gender = 'm' LIMIT 10
$connection->findAll('users', ['gender' => 'm'], ['limit' => 10]);

Creates new classes under "namespace" by array access. New objects are injected the Connection instance. If no class is found, a virtual table class is created.

# new App\Users($connection) if it exists
$users = $connection['users'];

# SELECT * FROM users WHERE id = 1
$users->find(['id' => 1]);

A Silex provider is also included and takes a namespace option in addition to the same options as the DoctrineServiceProvider

$app->register(new Tabler\Provider\DbServiceProvider, [
  'db.options' => [
    'driver' => 'pdo_sqlite',
    'path' => ':memory:',
    'namespace' => 'App\\Model'
  ]
]);

Example controller

$app->get('/users/{id}', function($id) use($app) {
  $user = $app['db']['users']->find(['id' => $id]);
  // if there is no table class, this is equivalent to
  // $app['db']->find('users', ['id' => $id])
});