NAME

Test::SQLite - SQLite setup/teardown for tests

VERSION

version 0.0410

SYNOPSIS

use DBI;
use Test::SQLite;

# An empty test db:
my $sqlite = Test::SQLite->new;
my $dbh = $sqlite->dbh;
# Fiddle with the test database...
$dbh->disconnect;

# Use an in-memory test db:
$sqlite = Test::SQLite->new(memory => 1);

# Copy a database file to the test db:
$sqlite = Test::SQLite->new(database => '/some/where/database.db');

# Use a schema file to create the test db:
$sqlite = Test::SQLite->new(
  schema   => '/some/where/schema.sql',
  db_attrs => { RaiseError => 1, AutoCommit => 0 },
);

# Explicitly use the dsn and db_attrs to connect:
$dbh = DBI->connect($sqlite->dsn, '', '', $sqlite->db_attrs);
# Fiddle with the test database...
$dbh->commit;
$dbh->disconnect;

DESCRIPTION

Test::SQLite is inspired by Test::PostgreSQL and Test::mysqld, and creates a temporary sqlite database to use in tests.

This module will also return the database dbh handle, dsn connection string, and db_attrs connection attributes.

ATTRIBUTES

database

The existing database to copy to create a new test database.

has_database

Boolean indicating that a database file was provided to the constructor.

schema

The SQL schema with which to create a test database.

* The SQL parsing done by this module does not handle triggers.

has_schema

Boolean indicating that a schema file was provided to the constructor.

memory

Create a test database in memory.

has_memory

Boolean indicating that memory was provided to the constructor.

db_attrs

DBI connection attributes.

Default: { RaiseError => 1, AutoCommit => 1 }

dsn

The database connection string. This is a computed attribute and an argument given to the constructor will be ignored.

dbh

A connected database handle based on the dsn and db_attrs. This is a computed attribute and an argument given to the constructor will be ignored.

METHODS

new

$sqlite = Test::SQLite->new;
$sqlite = Test::SQLite->new(%arguments);

Create a new Test::SQLite object.

SEE ALSO

The t/01-methods.t file in this distribution.

The eg/dbic.t example test in this distribution.

DBI

File::Copy

File::Temp

Moo

THANK YOU

Kaitlyn Parkhurst (SYMKAT) <symkat@symkat.com>

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2022 by Gene Boggs.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.