Merql
Apply

Dry Run Preview

DryRun::generate() produces human-readable SQL statements with values interpolated inline. Use it to review what a merge would do before applying it to the database.

use Merql\Apply\DryRun;

$statements = DryRun::generate($result);

foreach ($statements as $sql) {
    echo "{$sql};\n";
}

Example output

INSERT INTO `posts` (`id`, `title`, `content`, `status`) VALUES ('42', 'New Post', 'Body text', 'draft');
UPDATE `posts` SET `title` = 'Updated Title', `status` = 'publish' WHERE `id` = '42';
DELETE FROM `posts` WHERE `id` = '99';

Value formatting

All values are wrapped in single quotes. Special characters are escaped for safe display:

CharacterEscaped as
\ (backslash)\\
' (single quote)''
\0 (null byte)\0
\n (newline)\n
\r (carriage return)\r

NULL values are rendered as the unquoted literal NULL:

UPDATE `posts` SET `subtitle` = NULL WHERE `id` = '42';

Parameters

DryRun::generate() accepts the same parameters as SqlGenerator::generate():

$statements = DryRun::generate(
    $result,
    base: $baseSnapshot,
    fkDependencies: ['comments' => ['posts']],
    driver: new SqliteDriver(),
);
ParameterTypeDescription
$resultMergeResultThe merge result to preview.
$base?SnapshotBase snapshot for identity columns. Falls back to $result->baseSnapshot().
$fkDependenciesarrayForeign key dependency map for ordering.
$driver?DriverDatabase driver for identifier quoting.

Dry run vs SqlGenerator

DryRun wraps SqlGenerator. The difference:

  • SqlGenerator::generate() returns ['sql' => '...', 'params' => [...]] arrays intended for PDO::prepare() and execute().
  • DryRun::generate() returns flat strings with values inlined, intended for humans to read.

Do not execute dry run output as SQL. It is formatted for display, not for safe execution. For executing merges, use Applier or SqlGenerator directly with prepared statements.

Using with the facade

Through the facade, capture a merge result and preview it:

use Merql\Merql;
use Merql\Apply\DryRun;

$result = Merql::merge('base', 'ours', 'theirs');

$statements = DryRun::generate($result);

foreach ($statements as $sql) {
    echo "{$sql};\n";
}

Or from the CLI with the --dry-run flag:

./bin/merql merge base ours theirs --dry-run

On this page