The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::SQLite - SQLite setup/teardown for tests

VERSION

version 0.0207

SYNOPSIS

  use DBI;
  use Test::SQLite;

  my $sqlite = Test::SQLite->new(database => '/some/where/production.db');

  my $dbh = $sqlite->dbh;

  $sqlite = Test::SQLite->new(
    schema   => '/some/where/schema.sql',
    db_attrs => { RaiseError => 1, AutoCommit => 0 },
  );

  $dbh = DBI->connect($sqlite->dsn, '', '', $sqlite->db_attrs);

DESCRIPTION

Test::SQLite is loosely inspired by Test::PostgreSQL and Test::mysqld, and creates a temporary db to use in tests. Unlike those modules, it is limited to setup/teardown of the test db given a database or schema SQL file. Also this module will return the database dbh handle and dsn connection string.

ATTRIBUTES

database

The database to copy.

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.

db_attrs

DBI connection attributes. Default: { RaiseError => 1, AutoCommit => 1 }

dsn

The database connection string.

dbh

A connected database handle based on the dsn and db_attrs.

METHODS

new

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

Create a new Test::SQLite object, which creates a temporary database given a database or schema.

BUILD

Ensure that we are given either a database or a schema and not both.

SEE ALSO

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

DBI

File::Copy

File::Temp

Moo

THANK YOU

Kaitlyn Parkhurst <symkat@symkat.com>

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 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.