pg: Module rename + more docs

This commit is contained in:
Yorhel 2025-02-11 10:54:01 +01:00
parent ccc2f1dbf0
commit 33fe0d98a8
7 changed files with 186 additions and 101 deletions

View file

@ -1,28 +1,28 @@
use v5.36;
use Test::More;
plan skip_all => $@ if !eval { require FU::PG; } && $@ =~ /Unable to load libpq/;
plan skip_all => $@ if !eval { require FU::Pg; } && $@ =~ /Unable to load libpq/;
die $@ if $@;
plan skip_all => 'Please set FU_TEST_DB to a PostgreSQL connection string to run these tests' if !$ENV{FU_TEST_DB};
sub okerr($sev, $act, $msg) {
is ref $@, 'FU::PG::error';
is ref $@, 'FU::Pg::error';
is $@->{severity}, $sev;
is $@->{action}, $act;
like "$@", $msg;
}
ok !eval { FU::PG->connect("invalid") };
ok !eval { FU::Pg->connect("invalid") };
okerr FATAL => connect => qr/missing "=" after "invalid"/;
ok FU::PG::lib_version() > 100000;
ok FU::Pg::lib_version() > 100000;
my $conn = FU::PG->connect($ENV{FU_TEST_DB})->text;
my $conn = FU::Pg->connect($ENV{FU_TEST_DB})->text;
$conn->_debug_trace(0);
is ref $conn, 'FU::PG::conn';
is ref $conn, 'FU::Pg::conn';
ok $conn->server_version > 100000;
is $conn->lib_version, FU::PG::lib_version();
is $conn->lib_version, FU::Pg::lib_version();
is $conn->status, 'idle';
subtest '$conn->exec', sub {
@ -35,7 +35,7 @@ subtest '$conn->exec', sub {
ok !defined $conn->exec('');
is $conn->exec('SELECT 1'), 1;
ok !eval { $conn->q('SELEXT')->params; };
ok !eval { $conn->q('SELEXT')->param_types; };
okerr ERROR => prepare => qr/syntax error/;
is $conn->exec('SET client_encoding=utf8'), undef;
@ -45,7 +45,7 @@ subtest '$conn->exec', sub {
subtest '$st prepare & exec', sub {
{
my $st = $conn->q('SELECT 1');
is_deeply $st->params, [];
is_deeply $st->param_types, [];
is_deeply $st->columns, [{ name => '?column?', oid => 23 }];
is $conn->exec('SELECT 1 FROM pg_prepared_statements'), 1;
is $st->exec, 1;
@ -55,7 +55,7 @@ subtest '$st prepare & exec', sub {
{
my $st = $conn->q("SELECT \$1::int AS a, \$2::char(5) AS \"\x{1F603}\"", 1, 2);
is_deeply $st->params, [ { oid => 23 }, { oid => 1042 } ];
is_deeply $st->param_types, [ 23, 1042 ];
is_deeply $st->columns, [
{ oid => 23, name => 'a' },
{ oid => 1042, name => "\x{1F603}", typemod => 9 },
@ -72,7 +72,7 @@ subtest '$st prepare & exec', sub {
like $@, qr/Statement expects 1 bind parameters but 0 were given/;
# prepare + describe won't let us detect empty queries, hmm...
is_deeply $conn->q('')->params, [];
is_deeply $conn->q('')->param_types, [];
is_deeply $conn->q('')->columns, [];
ok !eval { $conn->q('')->exec; 1 };

View file

@ -1,11 +1,11 @@
use v5.36;
use Test::More;
plan skip_all => $@ if !eval { require FU::PG; } && $@ =~ /Unable to load libpq/;
plan skip_all => $@ if !eval { require FU::Pg; } && $@ =~ /Unable to load libpq/;
die $@ if $@;
plan skip_all => 'Please set FU_TEST_DB to a PostgreSQL connection string to run these tests' if !$ENV{FU_TEST_DB};
my $conn = FU::PG->connect($ENV{FU_TEST_DB});
my $conn = FU::Pg->connect($ENV{FU_TEST_DB});
ok !eval { $conn->q('SELECT $1::aclitem', '')->exec; 1 };
like $@, qr/Unable to send or receive/;

View file

@ -3,11 +3,11 @@ use Test::More;
no warnings 'experimental::builtin';
use builtin qw/true false is_bool created_as_number/;
plan skip_all => $@ if !eval { require FU::PG; } && $@ =~ /Unable to load libpq/;
plan skip_all => $@ if !eval { require FU::Pg; } && $@ =~ /Unable to load libpq/;
die $@ if $@;
plan skip_all => 'Please set FU_TEST_DB to a PostgreSQL connection string to run these tests' if !$ENV{FU_TEST_DB};
my $conn = FU::PG->connect($ENV{FU_TEST_DB});
my $conn = FU::Pg->connect($ENV{FU_TEST_DB});
$conn->_debug_trace(0);
# TODO: Test behavior of magic bind params