Adding DB.pm

This commit is contained in:
sergiotarxz 2021-11-11 22:49:35 +01:00
parent 8c43403318
commit 42f234e103

View 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;