litek/tabler

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

Maintainers

Details

github.com/litek/tabler

Source

Issues

Installs: 22

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/litek/tabler

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

This package is not auto-updated.

Last update: 2025-10-11 18:47:13 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])
});