Acrux-DBI
view release on metacpan or search on metacpan
has 'model' => sub {
WWW::Altair::Model->new(
$_[0]->conf->latest("/modelurl")
);
};
```
Ð ÑÑом пÑимеÑе модÑÐ»Ñ Ð¼Ð¾Ð´ÐµÐ»Ð¸ подклÑÑаеÑÑÑ Ð² оÑновном клаÑÑе ÑеÑвеÑа [WWW::Suffit::Server](https://metacpan.org/pod/WWW::Suffit::Server), а ÑкземплÑÑ Ð¼Ð¾Ð´ÐµÐ»Ð¸ ÑоздаÑÑÑÑ Ð...
```text
mysql://username:password@hostname/altair?mysql_auto_reconnect=1
mariadb://username:password@hostname/altair?mariadb_auto_reconnect=1
sqlite:///var/lib/altair/altair.db?sqlite_unicode=1
```
Ðалее ÑÐºÐ°Ð·Ð°Ð½Ð½Ð°Ñ URL ÑÑÑока бÑÐ´ÐµÑ Ð¿ÑеобÑазована авÑомаÑиÑеÑки в DSN бÑдÑÑего ÑоединениÑ
## Connect
ÐÑи запÑÑке WEB ÑеÑвеÑа и пеÑеÑ
оде на главнÑÑ ÑÑÑаниÑÑ ÑеÑÑового ÑайÑа бÑÐ´ÐµÑ Ð¾ÑÑÑеÑÑвлен "вÑ
од" в обÑабоÑÑик ÑÑого маÑÑÑÑÑа `WWW::Altair::Server::Alp...
lib/Acrux/DBI.pm view on Meta::CPAN
my $options = $dbi->options;
This method returns options that will be used for generating the connection DSN
Default: all passed options to constructor merged with system defaults:
RaiseError => 0,
PrintError => 0,
PrintWarn => 0,
=head2 password
my $password = $dbi->password;
This is the L<Mojo::URL/password> that will be used for generating the connection DSN
default: none
=head2 ping
$dbi->ping ? 'OK' : 'Database session is expired';
Checks the connection to database
=head2 port
lib/Acrux/DBI.pm view on Meta::CPAN
my $opts = $self->{opts}; # defaults
my $query = $self->{uri}->query;
my %params = ();
$params{$_} = $query->param($_) for @{$query->names};
return { (%$opts, %params) } ; # merge defaults and URL params
}
sub username {
my $self = shift;
return $self->{uri}->username // '';
}
sub password {
my $self = shift;
return $self->{uri}->password // '';
}
sub userinfo {
my $self = shift;
return $self->{uri}->userinfo // '';
}
sub database {
my $self = shift;
my $u = $self->{uri};
my $dr = $self->driver;
my $db = '';
lib/Acrux/DBI.pm view on Meta::CPAN
sub errstr {
my $self = shift;
return $self->dbh->errstr // $DBI::errstr if defined($self->dbh) && $self->dbh->can('errstr');
return $DBI::errstr;
}
# Database methods
sub connect {
my $self = shift;
$self->{error} = '';
my $dbh = DBI->connect($self->dsn, $self->username, $self->password, $self->options);
if ($dbh) {
$self->{dbh} = $dbh;
printf STDERR "Connected to '%s'\n", $self->dsn if DEBUG;
} else {
$self->{error} = $DBI::errstr || "DBI->connect failed";
$self->{dbh} = undef;
}
return $self;
}
sub connect_cached {
my $self = shift;
$self->{error} = '';
my %opts = %{($self->options)};
$opts{private_cachekey} = $self->cachekey;
my $dbh = DBI->connect_cached($self->dsn, $self->username, $self->password, {%opts});
if ($dbh) {
$self->{dbh} = $dbh;
printf STDERR "Connected (cached) to '%s'\n", $self->dsn if DEBUG;
} else {
$self->{error} = $DBI::errstr || "DBI->connect failed";
$self->{dbh} = undef;
}
return $self;
}
sub disconnect {
# URL: 'postgres://foo:pass@localhost/mydb?PrintError=1&foo=123'
{
my $dbi = Acrux::DBI->new(undef, bar => 'baz');
$dbi->url('postgres://foo:pass@localhost/mydb?PrintError=1&foo=123');
is($dbi->driver, 'postgres', 'Driver (scheme) is postgres');
is($dbi->host, 'localhost', 'Host is localhost');
is($dbi->port, '', 'Port is null');
is($dbi->userinfo, 'foo:pass', 'Userinfo is foo:pass');
is($dbi->username, 'foo', 'Username is foo');
is($dbi->password, 'pass', 'Password is pass');
is($dbi->database, 'mydb', 'Password is mydb');
is($dbi->dsn, 'DBI:Pg:dbname=mydb;host=localhost', 'DSN is DBI:Pg:dbname=mydb;host=localhost');
#note explain $dbi->cachekey;
}
done_testing;
1;
__END__
t/03-connect.t view on Meta::CPAN
$dbi = Acrux::DBI->new($url, autoclean => 1);
is($dbi->{autoclean}, 1, 'autoclean = 1');
$dbi->connect;
ok(!$dbi->error, 'Connect to ' . $dbi->dsn) or diag $dbi->error;
ok $dbi->ping, 'Connected';
#is($dbi->driver, 'postgres', 'Driver (scheme) is postgres');
#is($dbi->host, 'localhost', 'Host is localhost');
#is($dbi->port, '', 'Port is null');
#is($dbi->userinfo, 'foo:pass', 'Userinfo is foo:pass');
#is($dbi->password, 'pass', 'Password is pass');
#is($dbi->database, 'mydb', 'Password is mydb');
#is($dbi->dsn, 'DBI:Pg:dbname=mydb;host=localhost', 'DSN is DBI:Pg:dbname=mydb;host=localhost');
#note explain {(DBI->installed_drivers)};
#my $res = $dbi->query('select * from monm');
#ok($res, 'select * from monm') or diag $dbi->error;
#note explain $res;
#note explain $res->array;
#note explain $res->arrays;
#note explain $res->collection_list;
( run in 1.920 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )