coderofsalvation / sql-table-diff
查找相似SQL表之间的差异。快速且优雅地比较大量数据集合
dev-master
2020-05-28 19:25 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-18 09:47:32 UTC
README
查找相似SQL表之间的差异。快速且优雅地比较大量数据集合。使用方法
$ composer require coderofsalvation/sql-diff-table
然后
// 2 db handlers since some frameworks use a separate read- and write-handler
$a = new SQLTableDiff( "sync_products_A", $dbConn, $dbConn );
$b = new SQLTableDiff( "sync_products_B", $dbConn, $dbConn );
// create 2 SQL tables based on the object fields
$a->createTableFromFields( array_keys($productsA[0]) );
$b->createTableFromFields( array_keys($productsB[0]) );
// fill the 2 SQL tables
foreach( $productsA as $p ) $sm->addRow( $p );
foreach( $productsB as $p ) $si->addRow( $p );
/*
* get products which have similar id-value but different stock-value
*/
$filter = (object)array(
'tableA' => "sync_products_A",
'tableB' => "sync_products_B",
'id' => "sku", // match on id field
'fields' => array("stock") // compare these fields
);
// SQL query is generated and the differences are returned as a result
$result = $sm->diff( $filter);
// there you go!
待办事项
- 使用闭包执行SQL查询
注意
每次查询中多次插入使用智能缓冲,这使得导入大量数据集变得超快。
提示
如果您想比较包含项目的大型集合,有时项目可能不兼容。例如,如果您想比较csv导出的产品与数据库中的产品。在这种情况下,您可能希望将集合转换为中间件格式。 DataMapper 允许您这样做。在将其映射到中间件格式后,然后您可以继续使用 createTableFormFields()
将其插入数据库。
许可协议
BSD