diff --git a/README.md b/README.md index f154fa0..45cadd6 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ purspgpp will replace this by something like the following: SELECT first_name, last_name FROM users WHERE id = $1 -""" :: Query (UUID × Unit) (String × String × Unit)) +""" :: Query (Tuple UUID Unit) (Tuple String (Tuple String Unit)) ``` You can integrate purspgpp into your build system. For example, here is a diff --git a/purspgpp b/purspgpp index df63b87..04d8b5c 100644 --- a/purspgpp +++ b/purspgpp @@ -72,10 +72,13 @@ sub process-module(libpq::Connection $conn, %mapping, Str:D $segment --> Str:D) multi sub process-query(libpq::Connection:D $conn, %mapping, Str:D $source --> Str:D) { $conn.prepare: '', $source; my $description = $conn.describe-prepared(''); - sub convert-types(@oids) { + sub convert-types(Int:D @oids --> Str:D) { die "unknown oid: $_" unless %mapping{$_}:exists for @oids; - (|@oids.map({%mapping{$_}}), "Unit").join(" × "); - }; + multi sub infix:() is assoc { "Unit" } + multi sub infix:(Str:D $a) { $a } + multi sub infix:(Str:D $a, Str:D $b --> Str:D) { "Tuple ($a) ($b)" } + [Tuple] |@oids.map({%mapping{$_}}), "Unit"; + } my $parameters = convert-types($description.parameters); my $fields = convert-types($description.fields); "(Query \"\"\"$source\"\"\" :: Query ($parameters) ($fields))";