NAME
Database::Temp::DB - This class represents the created database to user
VERSION
version 0.003
SYNOPSIS
my $db = Database::Temp->new(
driver => 'SQLite',
);
my $dbh = $db->dbh;
my $rows = $dbh->selectall_arrayref(
"SELECT 1, 1+2",
);
DESCRIPTION
The end user should never create this class directly. Database::Temp uses this class to create an object which represents the database just created by Database::Temp.
This class, when instantiated into an object, contains everything user needs to access the created temporary database, regardless of it database engine.
METHODS
driver
The short name of the Database::Temp driver, for example, in the case of Database::Temp::Driver::SQLite the value would be SQLite. Read-only.
name
Name of the database. Read-only.
cleanup
A boolean variable. Do we do cleanup? Depends on the DB driver what cleanup would be, e.g. in the case of SQLite, cleanup means erasing the database file. In the case of Postgres, cleanup would be dropping the database.
User can change this value. Value 1 means cleanup will be done, value 0 means no cleanup.
Default value is true: database will be erased when this object drops out of the scope.
init
Reference to the subroutine which is executed immediately after database creation. Therefore, this action has already been executed by the time user gets hold of this object. Read-only.
deinit
Reference to the subroutine which is executed immediately before database is demolished. User can change this value. Default value is pointer to an empty subroutine.
dsn
username
password
attr
These four fields are required to make a connection to a database. Read-only.
dsn, username and password are strings. attr is a hashref.
Most likely user would not use these directly, but instead use the method connection_info
. See below.
info
This field can contain other related information which is not required for establishing connection and creating a database handle, but which can be useful to the user or required by the driver when doing cleanup. Read-only.
connection_info
This method returns a list of connection information details which can be fed directly into DBI-
connect()> method.
my $dbh = DBI->connect( $temp_db->connection_info );
AUTHOR
Mikko Koivunalho <mikkoi@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2023 by Mikko Johannes Koivunalho.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.