Skip to content

Find differences between 2 similar SQL tables in. Compare large collections of data fast and stylish in PHP

License

Notifications You must be signed in to change notification settings

coderofsalvation/sql-diff-table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL Table Diff

Find differences between 2 similar SQL tables. Compare large collections of data fast and stylish.

Usage

$ composer require coderofsalvation/sql-diff-table

And then

// 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!

Todo

  • use closure for SQL query execution

Notes

Multiple-insertions-per-query takes place using smart-buffering, which makes importing large datasets ultrafast.

Hint

If you want to compare large collections with items, sometimes the items are not compatible. For example, if you want to compare products from an csv export with products in your database. In that case you might want to transform the collections to a middleware-format. DataMapper allows you to do that. After you mapped it to your middleware-format, then you can proceed inserting it into the db using createTableFormFields()

License

BSD

About

Find differences between 2 similar SQL tables in. Compare large collections of data fast and stylish in PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages