Use Tuple in favor of ×

This commit is contained in:
rightfold 2016-12-26 02:43:06 +01:00
parent 8d7af01288
commit c759418c67
2 changed files with 7 additions and 4 deletions

View File

@ -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

View File

@ -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:<Tuple>() is assoc<right> { "Unit" }
multi sub infix:<Tuple>(Str:D $a) { $a }
multi sub infix:<Tuple>(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))";