承接 baddum/sql418 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

baddum/sql418

最新稳定版本:v1.2.0

Composer 安装命令:

composer require baddum/sql418

包简介

A library for extensible SQL requests

关键字:

README 文档

README

Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage Total Downloads License

SQL418 is a small PHP library for extensible SQL requests.

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

  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:

$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:

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:

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:

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

You can also use all the features together:

$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:

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:

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:

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.

统计信息

  • 总下载量: 23
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-27