yiisoft/data-db
Composer 安装命令:
composer require yiisoft/data-db
包简介
Database query adapter for Yii Data
关键字:
README 文档
README
Yii Data DB
The package provides data reader implementation based on Yii DB query and a set of DB-specific filters.
Detailed build statuses:
| RDBMS | Status |
|---|---|
| SQLite | |
| MySQL | |
| PostgreSQL | |
| Microsoft SQL Server | |
| Oracle |
Requirements
- PHP 8.1 - 8.5.
Installation
The package could be installed with Composer:
composer require yiisoft/data-db
General usage
The QueryDataReader wraps a database query to provide a flexible data reading interface:
use Yiisoft\Data\Db\QueryDataReader; use Yiisoft\Data\Reader\Filter\Equals; use Yiisoft\Data\Reader\Filter\GreaterThan; use Yiisoft\Data\Reader\Filter\Like; use Yiisoft\Data\Reader\Filter\AndX; use Yiisoft\Data\Reader\Sort; use Yiisoft\Db\Query\Query; $query = (new Query($db))->from('customer'); $dataReader = new QueryDataReader($query); // Iterate through results foreach ($dataReader->read() as $customer) { // ... process each customer ... } // Read a single record $customer = $dataReader->readOne(); // Get total count $total = $dataReader->count(); // Sorting $sort = Sort::any(['name', 'email'])->withOrderString('-name,email'); $dataReader = $dataReader->withSort($sort); // Filtering $filter = new AndX( new Equals('status', 'active'), new GreaterThan('age', 18), new Like('name', 'John') ); $dataReader = $dataReader->withFilter($filter); // Pagination $dataReader = $dataReader ->withOffset(20) ->withLimit(10);
Field mapping
Map data reader field names to database columns:
use Yiisoft\Data\Db\QueryDataReader; use Yiisoft\Data\Reader\Filter\Equals; $dataReader = new QueryDataReader( query: $query, fieldMapper: [ 'userName' => 'user_name', 'createdAt' => 'created_at', ] ); // Now you can filter and sort by 'userName' and it will use 'user_name' column $filter = new Equals('userName', 'admin');
Batch processing
Process large datasets in batches to reduce memory usage:
use Yiisoft\Data\Db\QueryDataReader; $dataReader = new QueryDataReader($query); $dataReader = $dataReader->withBatchSize(100); foreach ($dataReader->read() as $item) { // Items are fetched in batches of 100 }
Documentation
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Data DB is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.
Maintained by Yii Software.
Support the project
Follow updates
yiisoft/data-db 适用场景与选型建议
yiisoft/data-db 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.37k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2021 年 10 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「db」 「data provider」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yiisoft/data-db 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yiisoft/data-db 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yiisoft/data-db 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Dibi is Database Abstraction Library for PHP
Time provider, providing consistent current date, time, datetime and timezone across the request.
Store your language lines in the database, yaml or other sources
Adds the EDTF data type to Wikibase
An Zend Expressive module for loading ZF2 or ZF3 modules.
统计信息
- 总下载量: 7.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 10
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2021-10-06