Permalink
Browse files

switch Pg to named params too

  • Loading branch information...
1 parent 51548e3 commit 2f5634763c58fb58f28c2d6abea3c9b1c3933418 @moritz moritz committed Apr 23, 2012
Showing with 13 additions and 24 deletions.
  1. +6 −10 lib/MiniDBD/Pg.pm6
  2. +7 −14 t/35-Pg-common.t
View
16 lib/MiniDBD/Pg.pm6
@@ -425,29 +425,25 @@ class MiniDBD::Pg:auth<mberends>:ver<0.0.1> {
method !errstr() is rw { $!errstr }
#------------------ methods to be called from MiniDBI ------------------
- method connect( Str $user, Str $password, Str $params, $RaiseError ) {
- my @params = $params.split(';');
- my %params;
- for @params -> $p {
- my ( $key, $value ) = $p.split('=');
- %params{$key} = $value;
- }
+ method connect(*%params) {
my $host = %params<host> // 'localhost';
my $port = %params<port> // 5432;
- my $database = %params<dbname> // 'postgres';
+ my $database = %params<dbname> // %params<database> // 'postgres';
+ my $user = %params<user> // die 'Missing <user> config';
+ my $password = %params<password> // die 'Missing <password> config';
my $conninfo = "host=$host port=$port dbname=$database user=$user password=$password";
my $pg_conn = PQconnectdb($conninfo);
my $status = PQstatus($pg_conn);
my $connection;
if $status eq CONNECTION_OK {
$connection = MiniDBD::Pg::Connection.bless(*,
:$pg_conn,
- :$RaiseError,
+ :RaiseError(%params<RaiseError>),
);
}
else {
$!errstr = PQerrorMessage($pg_conn);
- if $RaiseError { die $!errstr; }
+ if %params<RaiseError> { die $!errstr; }
}
return $connection;
}
View
21 t/35-Pg-common.t
@@ -4,21 +4,14 @@ use Test;
use MiniDBI;
# Define the only database specific values used by the common tests.
-my ( $*mdriver, $*test_dsn, $*test_user, $*test_password );
-{
- # Define values that are relevant only to Postgres
- my $hostname = 'localhost';
- my $port = 5432;
- my $database = 'zavolaj';
- # Set up the common variables with the Postgres specific values
- $*mdriver = 'Pg';
- $*test_dsn = "MiniDBI:$*mdriver" ~ ":dbname=$database;"
- ~ "host=$hostname;port=$port";
- $*test_user = 'testuser';
- $*test_password = 'testpass';
-}
-
+my ( $*mdriver, %*opts ) = 'Pg';
+%*opts<host> = 'localhost';
+%*opts<port> = 5432;
+%*opts<database> = 'zavolaj';
+%*opts<user> = 'testuser';
+%*opts<password> = 'testpass';
my $dbh;
+
my $post_connect_cb = {
my $dbh = @_.shift;
$dbh.do('SET client_min_messages = warning');

0 comments on commit 2f56347

Please sign in to comment.