Simple Transformation
The package includes a powerful, database-agnostic DSL for transforming your data after it has been extracted. This allows you to perform complex operations like joins (lookups), string manipulation, and math entirely within your database, ensuring high performance.
Basic Usage
Use the transform() method to define a transformation pipeline. The Expr class provides a fluent API for building expressions.
This simple example will take a table called raw_products, and:
- Copy the
skucolumn, renaming it toremote_id. - Create a single
full_namecolumn, created by combining thebrandandnamecolumns with a space.
use Andach\ExtractAndTransform\Transform\Expr;
ExtractAndTransform::transform('Clean Products')
->from('raw_products')
->select([
// Simple Rename
'sku' => 'remote_id',
// Concatenation
'full_name' => Expr::concat(Expr::col('brand'), ' ', Expr::col('name')),
// Static Mapping (Case Statement)
'is_active' => Expr::map('status', ['live' => 1])->default(0),
// Math Operations
'tax_amount' => Expr::col('price')->multiply(0.2),
// Lookups (Left Joins)
'category_name' => Expr::lookup('categories', 'cat_id', 'id', 'name'),
])
->toTable('clean_products')
->run();