2017 © Pedro Peláez
 

library easy-sql

Easiest SQL abstraction ever

image

crodas/easy-sql

Easiest SQL abstraction ever

  • Monday, February 29, 2016
  • by crodas
  • Repository
  • 1 Watchers
  • 6 Stars
  • 43 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

EasySQL

Easiest SQL abstraction ever, heavily inspired by yesql, (*1)

Concepts

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)

How does it work?

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)

The Versions

29/02 2016

dev-master

9999999-dev

Easiest SQL abstraction ever

  Sources   Download

MIT

The Requires

 

The Development Requires

by Cesar Rodas