-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
202 lines (127 loc) · 5.59 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
NAME
DBIx::QuickDB - Quickly start a db server.
DESCRIPTION
This library makes it easy to spin up a temporary database server for
any supported driver. PostgreSQL, MySQL and SQLite are the initially
supported drivers.
SYNOPSIS
These are nearly identical, creating databases that can be retrieved by
name globally. The difference is that the first will build them at
compile-time and will provide constants for accessing them. The second
will build them at run-time and you have to store them in variables.
DB CONSTANTS
use DBIx::QuickDB MYSQL_DB => {driver => 'MySQL'};
use DBIx::QuickDB PSQL_DB => {driver => 'PostgreSQL'};
my $m_dbh = MYSQL_DB->connect;
my $p_dbh = PSQL_DB->connect;
...
DB ON THE FLY
use DBIx::QuickDB;
my $msql = DBIx::QuickDB->build_db(mysql_db => {driver => 'MySQL'});
my $psql = DBIx::QuickDB->build_db(pg_db => {driver => 'PostgreSQL'});
my $m_dbh = $msql->connect;
my $p_dbh = $psql->connect;
...
ENV VARS
QDB_TMPDIR
Set this env var if you want QDB to use a temp dir other than the
default.
METHODS
$db = DBIx::QuickDB->build_db();
$db = DBIx::QuickDB->build_db($name);
$db = DBIx::QuickDB->build_db(\%spec);
$db = DBIx::QuickDB->build_db($name => \%spec);
If a $name is provided then the database will be named. If the named
database has already been created it will be returned ignoring any
other arguments. If the named db does not yet exist it will be
created.
If a %spec hashref is provided it will be used to construct the
database. See "SPEC HASH" for what is supported in %spec.
($bool, $fqd, $why ) = DBIx::QuickDB->check_driver($driver => \%spec);
The first argument must be a driver name. The name may be shorthand
IE "PostgreSQL" or it can be a fully qualified module name like
"DBIx::QuickDB::Driver::PostgreSQL".
The second argument is option, but when present must be a spec hash.
See "SPEC HASH" for what is supported in %spec.
This method returns a sequence of 3 values:
$bool
True if the driver is viable for the specifications. False if the
driver cannot be used.
$fqd
The full package name for the driver.
$why
If $bool is false then this will have an explanation for why the
driver is not viable.
SPEC HASH
Here is an overview of all options allowed:
my %spec = (
autostart => BOOL,
autostop => BOOL,
bootstrap => BOOL,
cleanup => BOOL,
dir => PATH,
driver => DRIVER_NAME,
drivers => ARRAYREF,
load_sql => FILE_OR_HASH,
nocache => BOOL,
);
autostart => BOOL
Defaults to true. When true the DB server will be started
automatically. If this is false then you will need to call $DB->start
yourself.
autostop => BOOL
Defaults to be the same as the 'autostart' key.
When true, the server will automatically be stopped when the program
ends.
bootstrap => BOOL
This defaults to true unless the 'dir' key is also provided, in which
case it will default to false.
When true this will cause the database to be bootstrapped into
existance in the specified (or generated) directory (IE the 'dir'
key).
cleanup => BOOL
This defaults to true unless the 'dir' key is also provided, in which
case it will default to false.
When true the databse directory will be completely deleted when the
program is finished. DO NOT USE THIS ON ANY IMPORTANT DATABASES.
dir => PATH
Use this key to point at an existing database directory. If not
provided a tempdir will be generated.
driver => DRIVER_NAME
This key lets you specify a driver to use. This must be a string, and
can either be the shorthand name IE 'PostgreSQL', or the full name IE
'DBIx::QuickDB::Driver::PostgreSQL'.
If this key is present then no other drivers will be tried or used.
If this key is missing then the 'drivers' key will be used. If both
keys are empty than any installed driver may be used.
drivers => ARRAYREF
If you are only a little picky about driver choice then you can use
this to list several drivers that are acceptible, the first one that
works will be used.
This key is ignored if the 'driver' key is specified. If both keys
are empty than any installed driver may be used.
load_sql => FILE_OR_HASH
This can be a path to an SQL file to load, an arrayref of several
files to load, or a structure with driver specific files to load.
load_sql => '/path/to/my/schema.sql'
load_sql => ['schema1.sql', 'schema2.sql']
load_sql => {
PostgreSQL => 'path/to/postgre.sql',
MySQL => 'path/to/my.sql',
SQLite => ['sqlite1.sql', 'sqlite2.sql'],
}
nocache => BOOL
Defaults to false. When set to true the database will not be
available globally by the name passed into build_db().
SOURCE
The source code repository for DBIx-QuickDB can be found at
https://github.com/exodist/DBIx-QuickDB/.
MAINTAINERS
Chad Granum <exodist@cpan.org>
AUTHORS
Chad Granum <exodist@cpan.org>
COPYRIGHT
Copyright 2020 Chad Granum <exodist7@gmail.com>.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See http://dev.perl.org/licenses/