{
    "href": "/post/2018/05/22/atlas-query-simple-sensible-sql/",
    "relId": "2018/05/22/atlas-query-simple-sensible-sql",
    "title": "Atlas.Query: Simple. Sensible. SQL.",
    "author": "pmjones",
    "markup": "html",
    "tags": [
        {
            "href": "/tag/atlas/",
            "relId": "atlas",
            "title": "Atlas",
            "author": null,
            "created": "2020-09-21 14:37:38 UTC",
            "updated": [
                "2020-09-21 14:37:38 UTC",
                "2023-06-22 02:17:41 UTC"
            ],
            "markup": "markdown"
        },
        {
            "href": "/tag/php/",
            "relId": "php",
            "title": "PHP",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        },
        {
            "href": "/tag/programming/",
            "relId": "programming",
            "title": "Programming",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        }
    ],
    "created": "2018-05-22 12:00:04 UTC",
    "updated": [
        "2018-05-22 12:00:04 UTC",
        "2020-10-29 21:54:55 UTC",
        "2020-10-29 21:55:59 UTC",
        "2020-10-29 21:56:15 UTC"
    ],
    "html": "<p>I am happy to announce that <a href=\"http://atlasphp.io/cassini/query/\">Atlas.Query</a> is now stable and ready for production<br>\nuse! Installaton is as easy as <code>composer require atlas/query ~1.0</code>.</p>\n<p>With Atlas.Query and any PDO instance, you can build <strong>and execute</strong> your queries in a single fluent series of method calls:</p>\n\n<pre><code><span class=\"x\">use Atlas\\Query\\Select;</span>\n\n<span class=\"x\">$rows = Select::new($pdo)</span>\n<span class=\"x\">    -&gt;columns('*')</span>\n<span class=\"x\">    -&gt;from('posts')</span>\n<span class=\"x\">    -&gt;where('id IN ', $ids)</span>\n<span class=\"x\">    -&gt;fetchAll();</span>\n\n<span class=\"x\">foreach ($rows as $row) {</span>\n<span class=\"x\">    // ...</span>\n<span class=\"x\">}</span>\n</code></pre>\n\n<p>If you prefer, you can exercise fine control over your PDO connection, use a query factory, or build your queries in smaller steps:</p>\n\n<pre><code><span class=\"x\">use Atlas\\Pdo\\Connection;</span>\n<span class=\"x\">use Atlas\\Query\\QueryFactory;</span>\n\n<span class=\"x\">$connection = Connection::new(</span>\n<span class=\"x\">    'mysql:host=localhost;dbname=testdb',</span>\n<span class=\"x\">    'username',</span>\n<span class=\"x\">    'password'</span>\n<span class=\"x\">);</span>\n\n<span class=\"x\">$queryFactory = new QueryFactory();</span>\n\n<span class=\"x\">$select = $queryFactory-&gt;newSelect($connection);</span>\n<span class=\"x\">$select-&gt;columns('*');</span>\n<span class=\"x\">$select-&gt;from('posts');</span>\n<span class=\"x\">$select-&gt;where('id = ', $id);</span>\n\n<span class=\"x\">$row = $select-&gt;fetchOne();</span>\n</code></pre>\n\n<p>Atlas.Query provides the full power of SQL at your fingertips \u2026</p>\n\n<pre><code><span class=\"x\">$select</span>\n<span class=\"x\">    -&gt;columns(...)</span>\n<span class=\"x\">    -&gt;from(...)</span>\n<span class=\"x\">    -&gt;join(...)</span>\n<span class=\"x\">    -&gt;where(...)</span>\n<span class=\"x\">    -&gt;groupBy(...)</span>\n<span class=\"x\">    -&gt;having(...)</span>\n<span class=\"x\">    -&gt;orderBy(...)</span>\n<span class=\"x\">    -&gt;limit(...)</span>\n<span class=\"x\">    -&gt;offset(...);</span>\n</code></pre>\n\n<p>\u2026 along with <a href=\"http://atlasphp.io/cassini/query/select.html#1-4-3-1-10\">UNIONs</a>, <a href=\"http://atlasphp.io/cassini/query/select.html#1-4-3-1-8\">paging</a>, <a href=\"http://atlasphp.io/cassini/query/select.html#1-4-3-3\">sub-selects</a>, <a href=\"http://atlasphp.io/cassini/query/binding.html\">inline value binding</a>, and all sorts of <a href=\"http://atlasphp.io/cassini/query/select.html#1-4-3-4\">fetch and yield styles</a>.</p>\n<p>Atlas.Query comes with <a href=\"http://atlasphp.io/cassini/query/insert.html\">INSERT</a>, <a href=\"http://atlasphp.io/cassini/query/update.html\">UPDATE</a>, and <a href=\"http://atlasphp.io/cassini/query/delete.html\">DELETE</a> builders as well:</p>\n\n<pre><code><span class=\"x\">use Atlas\\Query\\Insert;</span>\n\n<span class=\"x\">$insert = Insert::new($pdo);</span>\n\n<span class=\"x\">// insert a row ...</span>\n<span class=\"x\">$insert-&gt;into('posts')</span>\n<span class=\"x\">    -&gt;columns([</span>\n<span class=\"x\">        'title' =&gt; $title,</span>\n<span class=\"x\">        'body' =&gt; $body,</span>\n<span class=\"x\">    ])</span>\n<span class=\"x\">    -&gt;raw('created_at', 'NOW()')</span>\n<span class=\"x\">    -&gt;perform();</span>\n\n<span class=\"x\">// ... and get back the autoincrement value:</span>\n<span class=\"x\">$post_id = $insert-&gt;getLastInsertId();</span>\n</code></pre>\n\n<p>Do you work on different project with different database 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.</p>\n<p>And if you discover you need more than just a query system, you\u2019ll have a clear refactoring path towards <a href=\"https://github.com/atlasphp/Atlas.Orm\">Atlas.Orm</a>. If you are looking for a modern, stable, easy-to-use query system, try Atlas.Query in your project! </p>\n<hr>\n<p>You can read the Reddit commentary on this post <a href=\"https://www.reddit.com/r/PHP/comments/8l9kax/atlas_query_simple_sensible_sql/\">here</a>.</p>\n"
}
