Add FU::SQL

Somewhat experimental, need to test this approach on a real site.
Looking pretty promising so far, though.
This commit is contained in:
Yorhel 2025-02-20 11:43:16 +01:00
parent 48d3fb86a5
commit 145d086bea
5 changed files with 504 additions and 0 deletions

View file

@ -1,5 +1,6 @@
use v5.36;
use Test::More;
use FU::SQL;
plan skip_all => $@ if !eval { require FU::Pg; } && $@ =~ /Unable to load libpq/;
die $@ if $@;
@ -8,11 +9,18 @@ plan skip_all => 'Please set FU_TEST_DB to a PostgreSQL connection string to run
my $conn = FU::Pg->connect($ENV{FU_TEST_DB});
$conn->_debug_trace(0);
is_deeply $conn->Q('SELECT', 1, '::int')->param_types, [23];
is_deeply $conn->Q('SELECT 1', IN([1,2,3]))->param_types, [1007];
is $conn->Q('SELECT 1', IN([1,2,3]))->val, 1;
ok !eval { $conn->q('SELECT $1::aclitem', '')->exec; 1 };
like $@, qr/Unable to send or receive/;
{
my $txn = $conn->txn;
is $txn->Q('SELECT 1', IN([1,2,3]))->val, 1;
$txn->exec(<<~_);
CREATE TYPE fupg_test_enum AS ENUM('a', 'b', 'ccccccccccccccccccc');
CREATE DOMAIN fupg_test_domain AS fupg_test_enum CHECK(value IN('a','b'));