litek/

tabler

此包的最新版本(dev-master)没有可用的许可信息。

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

This package is not auto-updated.

Last update: 2024-09-28 13:20:18 UTC


README

基于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]);

通过数组访问在"命名空间"下创建新类。新对象注入连接实例。如果没有找到类,则创建一个虚拟表类。

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

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

还包括Silex提供者,除了与DoctrineServiceProvider相同的选项外,还包括命名空间选项。

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

示例控制器

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