Atlas.Query: Simple. Sensible. SQL.
I am happy to announce that Atlas.Query is now stable and ready for production
use! Installaton is as easy as composer require atlas/query ~1.0
.
With Atlas.Query and any PDO instance, you can build and execute your queries in a single fluent series of method calls:
use Atlas\Query\Select;
$rows = Select::new($pdo) ->columns('*') ->from('posts') ->where('id IN ', $ids) ->fetchAll();
foreach ($rows as $row) { // ... }
If you prefer, you can exercise fine control over your PDO connection, use a query factory, or build your queries in smaller steps:
use Atlas\Pdo\Connection; use Atlas\Query\QueryFactory;
$connection = Connection::new( 'mysql:host=localhost;dbname=testdb', 'username', 'password' );
$queryFactory = new QueryFactory();
$select = $queryFactory->newSelect($connection); $select->columns('*'); $select->from('posts'); $select->where('id = ', $id);
$row = $select->fetchOne();
Atlas.Query provides the full power of SQL at your fingertips …
$select ->columns(...) ->from(...) ->join(...) ->where(...) ->groupBy(...) ->having(...) ->orderBy(...) ->limit(...) ->offset(...);
… along with UNIONs, paging, sub-selects, inline value binding, and all sorts of fetch and yield styles.
Atlas.Query comes with INSERT, UPDATE, and DELETE builders as well:
use Atlas\Query\Insert;
$insert = Insert::new($pdo);
// insert a row ... $insert->into('posts') ->columns([ 'title' => $title, 'body' => $body, ]) ->raw('created_at', 'NOW()') ->perform();
// ... and get back the autoincrement value: $post_id = $insert->getLastInsertId();
Do you work on different project with different datbase backends? Atlas.Query lets you use the same interface for them all, while not restricting you to a common subset of functionality. MySQL, PostgreSQL, SQLite, and SQL Server are all supported explicitly.
And if you discover you need more than just a query system, you’ll have a clear refactoring path towards Atlas.Orm. If you are looking for a modern, stable, easy-to-use query system, try Atlas.Query in your project!