Skip to content

Latest commit

 

History

History
54 lines (44 loc) · 1.41 KB

README.md

File metadata and controls

54 lines (44 loc) · 1.41 KB

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])
});