From c759418c6720e5748fe1d82a345ac5563e5ba569 Mon Sep 17 00:00:00 2001 From: rightfold Date: Mon, 26 Dec 2016 02:43:06 +0100 Subject: [PATCH] =?UTF-8?q?Use=20Tuple=20in=20favor=20of=20=C3=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- purspgpp | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) 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))";