承接 jasny/persist-sql-query 相关项目开发

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

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

jasny/persist-sql-query

最新稳定版本:v3.0.0-alpha1

Composer 安装命令:

composer require jasny/persist-sql-query

包简介

SQL Query builder and parser

README 文档

README

jasny-banner

Persist - SQL Query

This library is designed to be the ultimate tool for building, splitting and modifying queries.

Automatic smart quoting helps against SQL injection and problems with reserved keywords.

Supported SQL dialects

  • Generic (ANSI standard)
  • MySQL
  • PostgreSQL (todo)
  • SQLite (todo)

Installation

composer install jasny/persist-sql-query

Examples

Add WHERE conditions and an OFFSET to a SELECT query

use Jasny\Persist\SQL\Query;

$query = (new Query("SELECT * FROM foo LEFT JOIN bar ON foo.bar_id = bar.id WHERE active = 1 LIMIT 25"))
    ->where('type', 'bike')
    ->where('price between ? and ?', [10, 20])
    ->page(3);

echo $query; // SELECT * FROM foo LEFT JOIN bar ON foo.bar_id = bar.id WHERE (active = 1) AND (`type` = 'bike') AND (`price` between 10 and 20) LIMIT 25 OFFSET 50

Map fields for an INSERT INTO ... SELECT ... ON DUPLICATE KEY query

use Jasny\Persist\SQL\Query;

$columns = [
    'ref' => 'ref',
    'man' => 'boy',
    'woman' => 'girl',
    'amount' => 'SUM(z.bucks)'
];

$build = Query::build('mysql');

$select = $build->select()->columns($columns)->from('foo')->innerJoin('z', 'foo.id = z.foo_id')->groupBy('foo.id');
$insert = $build->insert()->into('abc')->columns(array_keys($columns))->set($select)->onDuplicateKeyUpdate();

echo $insert; // INSERT INTO `abc` (`ref`, `man`, `woman`, `amount`)
              //   SELECT `ref` AS `ref`, `boy` AS `man`, `girl` AS `woman`, SUM(`z`.`bucks`) AS `amount` FROM `foo` LEFT JOIN `z` ON `foo`.`id` = `z`.`foo_id` GROUP BY `foo`.id`
              //   ON DUPLICATE KEY UPDATE `ref` = VALUES(`ref`), `man` = VALUES(`man`), `woman` = VALUES(`woman`), `amount` = VALUES(`amount`)

统计信息

  • 总下载量: 451.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 33
  • 点击次数: 6
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 33
  • Watchers: 6
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04