ackintosh / higher
ORM library
dev-master
2014-12-20 07:49 UTC
Requires
- symfony/yaml: *
Requires (Dev)
This package is auto-updated.
Last update: 2024-10-16 09:53:36 UTC
README
[Work in progress] Higher is a ORM library, written in PHP.
Description
Named "Higher" was inspired by this song. (「゚Д゚)「 gow gow
Requirement
PHP 5.4 or higher
Usage
<?php $config = (new Ackintosh\Higher\Config()) ->setConfigFile('config.yml') ->parse() ->setTableDir(__DIR__ . '/table'); $repo = new Ackintosh\Higher\Repository($config); $connectionManager = new Ackintosh\Higher\ConnectionManager($config); $query = new Ackintosh\Higher\Query($connectionManager); $users = $repo->get('users'); $orders = $repo->get('orders');
SELECT
$res = $query->select([ [$users, 'name', 'addr'], [$orders, 'total'], ]) ->from($users) ->join($orders, ['id' => 'user_id']) ->where( function ($expr) use ($users, $orders) { $expr->_($users, ['id', '=', 2]); $expr->_or($users, ['id', '=', 3]); }, 'AND', function ($expr) use ($users, $orders) { $expr->_($users, ['id', '=', 2]); $expr->_or($users, ['id', '=', 3]); } ) ->useMaster()// use the master DB explicitly. ->execute();
SELECT `users`.`name` as `users.name`, `users`.`addr` as `users.addr`, `orders`.`total` as `orders.total` FROM `users` INNER JOIN `orders` ON `users`.`id` = `orders`.`user_id` WHERE ( `users`.`id` = ? OR `users`.`id` = ? ) AND ( `users`.`id` = ? OR `users`.`id` = ? )
INSERT
<?php $connectionManager->begin(); $res = $query->insert($users, ['name', 'created']) ->values(['testname', date('Y-m-d H:i:s')]) ->execute(); $connectionManager->commit();
INSERT INTO `users` ( `name`,`created` ) VALUES ( ?,? )
UPSERT
<?php $connectionManager->begin(); $res = $query->upsert($users, ['name', 'created']) ->values(['testname', date('Y-m-d H:i:s')]) ->execute(); $connectionManager->commit();
INSERT INTO `users` ( `name`,`created` ) VALUES ( ?,? ) ON DULPLICATE KEY UPDATE `name` = ?,`created` = ?
UPDATE
<?php $ret = $query->update($users) ->set(['name' => 'foo', 'addr' => 'bar']) ->where( function ($expr) use ($users) { $expr->_($users, ['id', '=', 2]); } )->execute();
UPDATE users SET `name` = ?, `addr` = ? WHERE ( `users`.`id` = ? )
OTHER
<?php $u = $users->newRecord(); $u->name = 'foo'; $u->created = date('Y-m-d H:i:s'); $query->save($u); // insert $u->name = 'bar'; $query->save($u); // update
Install
{ "require": { "ackintosh/higher": "*" } }
$ php composer.phar install