Skip to content

Commit 7c4f5eb

Browse files
theoryoalders
authored andcommitted
Add YugabyteDB
Its default port is 5433, but since the DBI interface uses DBD::Pg, always explicitly pass the port in the DBI params, because otherwise DBD::Pg woudl assume the default was 5432.
1 parent b157815 commit 7c4f5eb

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-2
lines changed

Changes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Revision history for Perl extension URI::db.
22

33
0.20
4-
- Added URI::cockroach.
4+
- Added URI::cockroach and URI::yugabyte.
55

66
0.19 2018-07-19T15:15:04Z
77
- Added URI::snowflake.

lib/URI/cockroach.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sub _dbi_param_map {
1010
my $self = shift;
1111
return (
1212
[ host => scalar $self->host ],
13-
[ port => scalar $self->port ],
13+
[ port => scalar $self->port ], # Always pass the port
1414
[ dbname => scalar $self->dbname ],
1515
);
1616
}

lib/URI/yugabyte.pm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package URI::yugabyte;
2+
use base 'URI::_db';
3+
our $VERSION = '0.20';
4+
5+
sub default_port { 5433 }
6+
sub dbi_driver { 'Pg' }
7+
sub canonical_engine { 'pg' }
8+
9+
sub _dbi_param_map {
10+
my $self = shift;
11+
return (
12+
[ host => scalar $self->host ],
13+
[ port => scalar $self->port ], # Always pass the port
14+
[ dbname => scalar $self->dbname ],
15+
);
16+
}
17+
18+
1;

lib/URI/yugabytedb.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package URI::yugabytedb;
2+
use base 'URI::yugabyte';
3+
our $VERSION = '0.20';
4+
5+
1;

t/dbi.t

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,36 @@ for my $spec (
448448
dbi => [ [host => 'foo'], [port => 123], [dbname => 'try'] ],
449449
qry => [ foo => 1, foo => 2, lol => 'yes' ],
450450
},
451+
{
452+
uri => 'db:yugabyte:',
453+
dsn => 'dbi:Pg:port=5433',
454+
dbi => [ [host => undef], [port => 5433], [dbname => undef] ],
455+
qry => [],
456+
},
457+
{
458+
uri => 'db:yugabyte://xxx:5432',
459+
dsn => 'dbi:Pg:host=xxx;port=5432',
460+
dbi => [ [host => 'xxx'], [port => 5432], [dbname => undef] ],
461+
qry => [],
462+
},
463+
{
464+
uri => 'db:yugabyte://foo:123/try?foo=1&foo=2&lol=yes',
465+
dsn => 'dbi:Pg:host=foo;port=123;dbname=try;foo=1;foo=2;lol=yes',
466+
dbi => [ [host => 'foo'], [port => 123], [dbname => 'try'] ],
467+
qry => [ foo => 1, foo => 2, lol => 'yes' ],
468+
},
469+
{
470+
uri => 'db:yugabytedb:',
471+
dsn => 'dbi:Pg:port=5433',
472+
dbi => [ [host => undef], [port => 5433], [dbname => undef] ],
473+
qry => [],
474+
},
475+
{
476+
uri => 'db:yugabytedb://foo:123/try?foo=1&foo=2&lol=yes',
477+
dsn => 'dbi:Pg:host=foo;port=123;dbname=try;foo=1;foo=2;lol=yes',
478+
dbi => [ [host => 'foo'], [port => 123], [dbname => 'try'] ],
479+
qry => [ foo => 1, foo => 2, lol => 'yes' ],
480+
},
451481
) {
452482
my $uri = $spec->{uri};
453483
ok my $u = URI->new($uri), "URI $uri";

t/engines.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ for my $spec (
5151
[ snowflake => 443, 'snowflake' ],
5252
[ cockroach => 26257, 'cockroach' ],
5353
[ cockroachdb => 26257, 'cockroach' ],
54+
[ yugabyte => 5433, 'pg' ],
55+
[ yugabytedb => 5433, 'pg' ],
5456
) {
5557
my ($engine, $port, $canon) = @{ $spec };
5658
my $prefix = "db:$engine";

0 commit comments

Comments
 (0)