2017 © Pedro Peláez
 

library sql-table-diff

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

image

coderofsalvation/sql-table-diff

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

  • Friday, August 28, 2015
  • by coderofsalvation
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

SQL Table Diff

, (*1)

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

Usage

$ composer require coderofsalvation/sql-diff-table

And then, (*3)

// 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., (*4)

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(), (*5)

License

BSD, (*6)

The Versions

28/08 2015

dev-master

9999999-dev

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

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0