Skip to content

Commit 4cd1567

Browse files
authored
Add PostgresRowSequence multi decode (vapor#232)
1 parent 262208c commit 4cd1567

File tree

3 files changed

+169
-1
lines changed

3 files changed

+169
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/// NOTE: THIS FILE IS AUTO-GENERATED BY dev/generate-postgresrowsequence-multi-decode.sh
2+
3+
#if swift(>=5.5) && canImport(_Concurrency)
4+
extension PostgresRowSequence {
5+
func decode<T0: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0)> {
6+
self.map { row in
7+
try row.decode(T0.self, context: context, file: file, line: line)
8+
}
9+
}
10+
11+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1)> {
12+
self.map { row in
13+
try row.decode((T0, T1).self, context: context, file: file, line: line)
14+
}
15+
}
16+
17+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2)> {
18+
self.map { row in
19+
try row.decode((T0, T1, T2).self, context: context, file: file, line: line)
20+
}
21+
}
22+
23+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3)> {
24+
self.map { row in
25+
try row.decode((T0, T1, T2, T3).self, context: context, file: file, line: line)
26+
}
27+
}
28+
29+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, T4: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3, T4).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3, T4)> {
30+
self.map { row in
31+
try row.decode((T0, T1, T2, T3, T4).self, context: context, file: file, line: line)
32+
}
33+
}
34+
35+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, T4: PostgresDecodable, T5: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3, T4, T5).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3, T4, T5)> {
36+
self.map { row in
37+
try row.decode((T0, T1, T2, T3, T4, T5).self, context: context, file: file, line: line)
38+
}
39+
}
40+
41+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, T4: PostgresDecodable, T5: PostgresDecodable, T6: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3, T4, T5, T6).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3, T4, T5, T6)> {
42+
self.map { row in
43+
try row.decode((T0, T1, T2, T3, T4, T5, T6).self, context: context, file: file, line: line)
44+
}
45+
}
46+
47+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, T4: PostgresDecodable, T5: PostgresDecodable, T6: PostgresDecodable, T7: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3, T4, T5, T6, T7).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3, T4, T5, T6, T7)> {
48+
self.map { row in
49+
try row.decode((T0, T1, T2, T3, T4, T5, T6, T7).self, context: context, file: file, line: line)
50+
}
51+
}
52+
53+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, T4: PostgresDecodable, T5: PostgresDecodable, T6: PostgresDecodable, T7: PostgresDecodable, T8: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3, T4, T5, T6, T7, T8)> {
54+
self.map { row in
55+
try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8).self, context: context, file: file, line: line)
56+
}
57+
}
58+
59+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, T4: PostgresDecodable, T5: PostgresDecodable, T6: PostgresDecodable, T7: PostgresDecodable, T8: PostgresDecodable, T9: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)> {
60+
self.map { row in
61+
try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9).self, context: context, file: file, line: line)
62+
}
63+
}
64+
65+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, T4: PostgresDecodable, T5: PostgresDecodable, T6: PostgresDecodable, T7: PostgresDecodable, T8: PostgresDecodable, T9: PostgresDecodable, T10: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)> {
66+
self.map { row in
67+
try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10).self, context: context, file: file, line: line)
68+
}
69+
}
70+
71+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, T4: PostgresDecodable, T5: PostgresDecodable, T6: PostgresDecodable, T7: PostgresDecodable, T8: PostgresDecodable, T9: PostgresDecodable, T10: PostgresDecodable, T11: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)> {
72+
self.map { row in
73+
try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11).self, context: context, file: file, line: line)
74+
}
75+
}
76+
77+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, T4: PostgresDecodable, T5: PostgresDecodable, T6: PostgresDecodable, T7: PostgresDecodable, T8: PostgresDecodable, T9: PostgresDecodable, T10: PostgresDecodable, T11: PostgresDecodable, T12: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)> {
78+
self.map { row in
79+
try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12).self, context: context, file: file, line: line)
80+
}
81+
}
82+
83+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, T4: PostgresDecodable, T5: PostgresDecodable, T6: PostgresDecodable, T7: PostgresDecodable, T8: PostgresDecodable, T9: PostgresDecodable, T10: PostgresDecodable, T11: PostgresDecodable, T12: PostgresDecodable, T13: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)> {
84+
self.map { row in
85+
try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13).self, context: context, file: file, line: line)
86+
}
87+
}
88+
89+
func decode<T0: PostgresDecodable, T1: PostgresDecodable, T2: PostgresDecodable, T3: PostgresDecodable, T4: PostgresDecodable, T5: PostgresDecodable, T6: PostgresDecodable, T7: PostgresDecodable, T8: PostgresDecodable, T9: PostgresDecodable, T10: PostgresDecodable, T11: PostgresDecodable, T12: PostgresDecodable, T13: PostgresDecodable, T14: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14).Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence<PostgresRowSequence, (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)> {
90+
self.map { row in
91+
try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14).self, context: context, file: file, line: line)
92+
}
93+
}
94+
}
95+
#endif

Sources/PostgresNIO/New/PostgresRowSequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import NIOCore
22
import NIOConcurrencyHelpers
33

44
#if swift(>=5.5) && canImport(_Concurrency)
5-
/// An async sequence of ``PSQLRow``s.
5+
/// An async sequence of ``PostgresRow``s.
66
///
77
/// - Note: This is a struct to allow us to move to a move only type easily once they become available.
88
struct PostgresRowSequence: AsyncSequence {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
7+
function gen() {
8+
how_many=$1
9+
10+
if [[ $how_many -ne 1 ]] ; then
11+
echo ""
12+
fi
13+
14+
#echo " @inlinable"
15+
#echo " @_alwaysEmitIntoClient"
16+
echo -n " func decode<T0: PostgresDecodable"
17+
for ((n = 1; n<$how_many; n +=1)); do
18+
echo -n ", T$(($n)): PostgresDecodable"
19+
done
20+
21+
echo -n ", JSONDecoder: PostgresJSONDecoder>(_: (T0"
22+
for ((n = 1; n<$how_many; n +=1)); do
23+
echo -n ", T$(($n))"
24+
done
25+
echo -n ").Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #file, line: Int = #line) "
26+
27+
echo -n "-> AsyncThrowingMapSequence<PostgresRowSequence, (T0"
28+
for ((n = 1; n<$how_many; n +=1)); do
29+
echo -n ", T$(($n))"
30+
done
31+
echo ")> {"
32+
33+
echo " self.map { row in"
34+
35+
if [[ $how_many -eq 1 ]] ; then
36+
echo " try row.decode(T0.self, context: context, file: file, line: line)"
37+
else
38+
echo -n " try row.decode((T0"
39+
40+
for ((n = 1; n<$how_many; n +=1)); do
41+
echo -n ", T$n"
42+
done
43+
echo ").self, context: context, file: file, line: line)"
44+
45+
fi
46+
47+
echo " }"
48+
echo " }"
49+
}
50+
51+
grep -q "ByteBuffer" "${BASH_SOURCE[0]}" || {
52+
echo >&2 "ERROR: ${BASH_SOURCE[0]}: file or directory not found (this should be this script)"
53+
exit 1
54+
}
55+
56+
{
57+
cat <<"EOF"
58+
/// NOTE: THIS FILE IS AUTO-GENERATED BY dev/generate-postgresrowsequence-multi-decode.sh
59+
EOF
60+
echo
61+
62+
echo "#if swift(>=5.5) && canImport(_Concurrency)"
63+
echo "extension PostgresRowSequence {"
64+
65+
# note:
66+
# - widening the inverval below (eg. going from {1..15} to {1..25}) is Semver minor
67+
# - narrowing the interval below is SemVer _MAJOR_!
68+
for n in {1..15}; do
69+
gen "$n"
70+
done
71+
echo "}"
72+
echo "#endif"
73+
} > "$here/../Sources/PostgresNIO/New/PostgresRowSequence-multi-decode.swift"

0 commit comments

Comments
 (0)