NAME
DBIO::Test::Storage - Fake storage for testing SQL generation without a database
VERSION
version 0.900000
SYNOPSIS
my $schema = DBIO::Test::Schema->connect('DBIO::Test::Storage', '');
my $rs = $schema->resultset('Artist')->search({ name => 'foo' });
# .as_query works without a database
my ($sql, @bind) = @{ ${$rs->as_query} };
# or execute and inspect the captured query log
my $storage = $schema->storage;
$storage->reset_captured;
$rs->all; # generates SQL, returns empty results
my @queries = $storage->captured_queries;
DESCRIPTION
A storage backend that generates SQL via DBIO::SQLMaker but never executes it against a real database. Every query is captured and can be inspected through "captured_queries".
This is useful for:
Testing SQL generation (SELECT, INSERT, UPDATE, DELETE)
Verifying ResultSet chaining produces expected queries
Schema metadata tests (columns, relationships, constraints)
Any test that only cares about what SQL would be generated
METHODS
connected
Always returns true. There is no real connection to check.
ensure_connected
No-op. We are always "connected".
disconnect
Sets connected state to false.
_execute
Overrides "_execute" in DBIO::Storage::DBI to capture the generated SQL and bind values instead of executing them.
Returns an empty result set.
captured_queries
Returns all captured queries as a list of hashrefs, each containing op, sql, and bind keys.
my @queries = $storage->captured_queries;
# ( { op => 'select', sql => 'SELECT ...', bind => [...] }, ... )
captured_sql_bind
Returns captured queries as arrayrefs of [$sql, @bind] pairs, compatible with "is_same_sql_bind" in SQL::Abstract::Test.
reset_captured
Clears the captured query log.
select
Returns a cursor that yields no rows.
mock
$storage->mock($sql_pattern, \@rows);
$storage->mock($sql_pattern, \@rows, \@columns);
$storage->mock(qr/SELECT.*FROM artist/i, [
[1, 'Caterwauler McCrae'],
[2, 'Random Boy Band'],
]);
Registers a mock result. When a query matches $sql_pattern (string or regexp), the given rows are returned. Mocks are checked in LIFO order -- later mocks override earlier ones. Each mock is consumed once unless registered with "mock_persistent".
mock_persistent
Like "mock" but the mock is not consumed after matching -- it keeps returning the same rows for every matching query.
clear_mocks
Removes all registered mocks.
set_auto_increment
$storage->set_auto_increment('Artist', 10);
Sets the auto-increment counter for a source so the next insert returns the given ID.
AUTHOR
DBIO & DBIx::Class Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.