2017 © Pedro Peláez
 

library sql418

A library for extensible SQL requests

image

baddum/sql418

A library for extensible SQL requests

  • Thursday, February 12, 2015
  • by tzi
  • Repository
  • 1 Watchers
  • 1 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

SQL418

Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage Total Downloads License, (*1)

SQL418 is a small PHP library for extensible SQL requests., (*2)

This library allows you to modify an existing SQL statement, by overriding some parts of it., (*3)

  1. Features
  2. Use cases
  3. How to Install
  4. How to Contribute
  5. Author & Community

Features

Use the extend() method to complete a request.
An example to add a WHERE clause to a SELECT request:, (*4)

$request = new Baddum\SQL418\Request('SELECT * from table');
echo $request->extend('WHERE id = 39');
// SELECT * FROM table WHERE id = 39;

You can override a defined part of a request.
An example to change the selected fields:, (*5)

echo $request->extend('SELECT name');
// SELECT name FROM table WHERE id = 39;

Use the & keyword to extend a part of a request.
An example to add a field to select:, (*6)

echo $request->extend('SELECT &, id');
// SELECT name, id FROM table WHERE id = 39;

You can change the type of a request.
An example to change a SELECT request to a DELETE one:, (*7)

echo $request->extend('DELETE');
// DELETE FROM table WHERE id = 39;

You can also use all the features together:, (*8)

$sql->extend('UPDATE SET name = "Albert" WHERE & AND right <> admin"');
echo $sql;
// UPDATE table SET name = "Albert" WHERE id = 39 AND right <> admin;

Use cases

Use case: DRYer requests

In the following example, the fetchById and deleteById requests share a common pattern:, (*9)

class UserModel {
  protected $SQLFetchById = 'SELECT * from user WHERE user.id=?';
  protected $SQLDeleteById = '';
  public function __construct() {
    $request = new Request($this->SQLFetchById);
    $this->SQLDeleteById = $request->extend('DELETE');
  }
}

Use case: extensible applications

In the following example, we extend the UserModel to do a soft delete:, (*10)

class UserModelSoftDelete extends UserModel {
  public function __construct() {
    $request = new Request($this->SQLFetchById);
    $this->SQLFetchById = $request->extend('WHERE & AND user.deleted = 0');
    $this->SQLDeleteById = $request->extend('UPDATE & SET user.deleted = 1');
  }
}

How to Install

This library package requires PHP 5.4 or later.
Install Composer and run the following command to get the latest version:, (*11)

composer require baddum/sql418:~1.2

How to Contribute

  1. Star the project!
  2. Tweet and blog about SQL418 and Let me know about it.
  3. Report a bug that you find
  4. Pull requests are highly appreciated. Please review the guidelines for contributing to go further.

Author & Community

SQL418 is under MIT License.
It was created & is maintained by Thomas ZILLIOX., (*12)

The Versions

12/02 2015

dev-master

9999999-dev https://github.com/Baddum/SQL418

A library for extensible SQL requests

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

sql pdo

29/01 2015

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/Baddum/SQL418

A library to extend SQL requests

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

sql pdo

29/01 2015

v1.2.0

1.2.0.0 https://github.com/Baddum/SQL418

A library to extend SQL requests

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

sql pdo

27/01 2015

v1.1.1

1.1.1.0 https://github.com/Baddum/SQL418

A library to extend SQL requests

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

sql pdo

27/01 2015

v1.1.0

1.1.0.0 https://github.com/Baddum/SQL418

A library to extend SQL requests

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

sql pdo

27/01 2015

v1.0.0

1.0.0.0 https://github.com/Baddum/SQL418

A library to extend SQL requests

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

sql pdo