Adding DB.pm
This commit is contained in:
parent
8c43403318
commit
42f234e103
45
cualsea-server/lib/Cualsea/Server/DB.pm
Normal file
45
cualsea-server/lib/Cualsea/Server/DB.pm
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package Cualsea::Server::DB;
|
||||||
|
|
||||||
|
use v5.30.0;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use DBI;
|
||||||
|
|
||||||
|
my $dbname = $ENV{HOME} . '/cualsea.db';
|
||||||
|
|
||||||
|
my @migrations = (
|
||||||
|
'CREATE TABLE options (
|
||||||
|
key TEXT PRIMARY KEY,
|
||||||
|
value TEXT
|
||||||
|
);',
|
||||||
|
'CREATE TABLE services (
|
||||||
|
name TEXT PRIMARY KEY,
|
||||||
|
init TEXT,
|
||||||
|
pidfile TEXT,
|
||||||
|
binpath TEXT
|
||||||
|
);'
|
||||||
|
);
|
||||||
|
|
||||||
|
sub dbh {
|
||||||
|
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbname", '', '' , {
|
||||||
|
AutoCommit => 1,
|
||||||
|
RaiseError => 1,
|
||||||
|
});
|
||||||
|
state $migrations_run = 0;
|
||||||
|
if (!$migrations_run) {
|
||||||
|
run_migrations($dbh);
|
||||||
|
$migrations_run = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub run_migrations {
|
||||||
|
my $dbh = shift;
|
||||||
|
|
||||||
|
my $migration = $dbh->selectrow_hashref(<<'EOF', {});
|
||||||
|
SELECT value FROM options WHERE key = 'migration'
|
||||||
|
EOF
|
||||||
|
|
||||||
|
}
|
||||||
|
1;
|
Loading…
Reference in New Issue
Block a user