dev-master
9999999-devEasiest SQL abstraction ever
MIT
The Requires
- crodas/notoj ^1.0.9
- ext-pdo ^1.0
- crodas/watch-files ^0.1.6
- symfony/finder ^2.7
- crodas/build ^0.1
- crodas/sql-parser ^0.1
The Development Requires
by Cesar Rodas
Wallogit.com
2017 © Pedro Peláez
Easiest SQL abstraction ever
Easiest SQL abstraction ever, heavily inspired by yesql, (*1)
I've been in a quest all my professional life, create the simplest SQL-abstraction for PHP. I gave up many times until I saw yesql's simplicity., (*2)
It's a tiresome task to reinvent SQL, and often in vain. You need to give away functionality (what makes SQL unique) or performance (something unthinkable for most web apps)., (*3)
EasySQL is heavily inspired by yesql, that means you have a different file with a list of SQL statements, which is compiled to a PHP class with all those operations., (*4)
-- This file is saved as queries/users.sql -- @name byEmail SELECT * FROM user WHERE email = $email LIMIT 1; -- @name getContacts SELECT u.id, u.name, u.email FROM user INNER JOIN contacts c (c.friend_of = u.id) WHERE c.user_id = $me; -- @name create INSERT INTO user(email) VALUES($email);
Then you need the following PHP bootstrap code to get it running:, (*5)
$repo = new EasySQL\EasySQL("queries", $pdo);
$users = $repo->getRepository("users");
// find and return a single row due to the `LIMIT 1`. To force
// a single row we can use @One annotation.
$me = $users->byEmail("crodas@php.net");
// All `INSERT` return the new created ID
$user_id = $users->create("crodas@php.net");
Underneath the EasySQL's compiler will read all files and their SQL statements and generate a PHP file with all the queries and bootstrap code., (*6)
Easiest SQL abstraction ever
MIT