monii/specification-sql-adapter
Composer 安装命令:
composer require monii/specification-sql-adapter
包简介
Specification SQL Adapter
README 文档
README
A SQL Adapter for Monii's implementation of the Specification pattern. It provides the tools to render a Specification into a SQL query.
Requirements
- PHP 5.5+
- monii/specification
- Something to consume SQL queries
Installation
$> composer require monii/specification-sql-adapter
Until a stable version has been released or if a development version is preferred, use:
$> composer require monii/specification-sql-adapter:@dev
Limitations
This library does not currently support joins and it may never do so. The underlying SqlQuery class is very
simple and needs more testing. It works well for what we've designed it to do but it could still use a lot
of work.
If you need something far more robust you could consider writing your own implementation. The Specification library is intended to support specialized rendering adapters to suite specific needs.
Example Usage
Repository
An easy example of how this renderer can be used with Monii's Specification package is by looking at an example
Doctrine DBAL repository implementation. In this case, our query builder is setup to know how to map two
properties to their corresponding table columns. We also assume that objectsFromRows is shared such
that it can take an array of plain arrays to construct the objects that were selected.
class DbalContactRepository implements ContactRepository { /** * @var Connection */ private $connection; /** * @var SqlSpecificationQueryBuilder */ private $sqlSpecificationQueryBuilder; /** * @var string */ private $tableName; /** * @param string $tableName */ public function __construct( Connection $connection, SqlSpecificationQueryBuilder $sqlSpecificationQueryBuilder, $tableName = 'terse_contact' ) { $this->connection = $connection; $this->sqlSpecificationQueryBuilder = $sqlSpecificationQueryBuilder; $this->tableName = $tableName; } /** * {@inheritdoc} */ public function findMatching(Specification $specification) { $sqlQuery = $this->sqlSpecificationQueryBuilder->buildQuery($specification, [ 'person.firstName' => 'person_first_name', 'person.lastName' => 'person_last_name', ]); $statement = $this->connection->prepare($sqlQuery->getSql($this->tableName)); $statement->execute($sqlQuery->getValues()); $results = $statement->fetchAll(); return $this->objectsFromRows($results); } }
License
MIT, see LICENSE.
Community
Want to get involved? Here are a few ways:
- Find us in the #monii IRC channel on irc.freenode.org.
- Mention @moniidev on Twitter.
monii/specification-sql-adapter 适用场景与选型建议
monii/specification-sql-adapter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.22k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 10 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sql」 「pattern」 「query builder」 「specification」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 monii/specification-sql-adapter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 monii/specification-sql-adapter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 monii/specification-sql-adapter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Query filtering in your frontend
Anax Database Active Record module for model classes.
A Laravel package for the Repository Design Pattern.
Inbox pattern process implementation for your Laravel Applications
Database/ORM-agnostic query construction helper
Laravel SQL Queries Dumper
统计信息
- 总下载量: 1.22k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-23