idct/database-comparator
最新稳定版本:1.0.0
Composer 安装命令:
composer require idct/database-comparator
包简介
Datasource sets comparing framework
README 文档
README
Basic framework for database comparisons. Allows to report differences between two datasources.
Useful especially when making a major change in an application which writes data to any data source and you would like to verify if nothing got broken. One could say that it allows to write easy black box tests.
contents
Framework provides so far:
PdoSource: for comparing databases to which PDO can be used as a connector.SourceInterface: interface for writing new compatible data source connectors.SimpleOutput: basic textual output for writing out differences to files.OutputInterface: interface for building new output writing objects.
usage
- Install by composer using:
composer require idct/database-comparator="^1.0"
or manually by downloading contents and placing in desired folder.
- Include all your files or the autoloader:
include "vendor/autoload.php";
- Build your comparison definitions:
Assuming you have a table with schema:
| id | irrelevant | value |
|---|---|---|
| 0 | somedate | 11 |
| 0 | somedate | 12 |
Create new objects:
$comparator = new Compare(); $objects = new PdoSource(); $pdo = new PDO(...); //your database connection details here
In case you compare within SAME database you can use same connector (same source)
$objects->setPdo($pdo) ->setQueryAll('select * from some_table limit :limit offset :offset') //limit and offset will be dynamically updated ->setQuerySingle('select * from some_table where {_keys}') ->setSingleKeys(['id']); $comparator->addSource('main', $objects) ->addSource('test', $objects); /* in this case we shall use the same source as for left calls it will use queryAll and for right ones querySingle */ $output = (new SimpleOutput()) ->setBaseFilename('somepath/comparison_{source}.log'); // {source} token will be dynamically replaced $comparator->setOutput($output) ->run(); //report differences var_dump($comparator->getDiffsCount());
- Special cases:
In some cases you want to omit some fields - for instance if your tables have the automatic "last updated" fields. You can do it in two ways:
- do not specify it within your queries (
QueryAll,QuerySingle) or in case it would be hard to do (like in SQL you would need to list all other fields) set "ignored fields":
$objects->setIgnoredFields(['last_updated']);
In case your tables / data sources have complex data sources just specify them as
next array elements in setSingleKeys, for example:
$objects->setSingleKeys(['id','sub_id']);
One of the most interesting features of the framework is option to alter results
just before comparison - this is very useful in situations when you know what
you have changed and want to check if you achieved it.
For instance: if you had an application which fills the sample table above and
you made a change to your app which causes writing of the value field with data
substracted by 2 you can still verify that using getSinglePreCheckTransformation
method.
$objects->setSinglePreCheckTransformation(function($their, $mine) { $mine['value'] += 2; return $mine; });
SinglePreCheckTransformation is meant to update the data from the current data
source and should return the updated set. So in case your application substracted
2 from value of field value of every row/entry you can add 2 back in order to
make the comparison using the code above.
contribution
In case you found any bugs, problems or would like to add some features... or write tests :) it is more than welcome! Please make the changes, add a pull request and I will merge it when it is possible. Thank you in advance!
idct/database-comparator 适用场景与选型建议
idct/database-comparator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 99 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「storage」 「db」 「validation」 「comparison」 「compare」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 idct/database-comparator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 idct/database-comparator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 idct/database-comparator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 99
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-27