Easiest SQL abstraction ever
This package is auto-updated.
Last update: 2020-05-12 10:04:13 UTC
Easiest SQL abstraction ever, heavily inspired by yesql
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).
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.
-- 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:
$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("email@example.com"); // All `INSERT` return the new created ID $user_id = $users->create("firstname.lastname@example.org");
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.