-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathgenerate-postgresrowsequence-multi-decode.sh
executable file
·111 lines (90 loc) · 2.83 KB
/
generate-postgresrowsequence-multi-decode.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
set -eu
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function genWithContextParameter() {
how_many=$1
if [[ $how_many -ne 1 ]] ; then
echo ""
fi
echo " @inlinable"
echo " @_alwaysEmitIntoClient"
echo -n " public func decode<T0: PostgresDecodable"
for ((n = 1; n<$how_many; n +=1)); do
echo -n ", T$(($n)): PostgresDecodable"
done
echo -n ", JSONDecoder: PostgresJSONDecoder>(_: (T0"
for ((n = 1; n<$how_many; n +=1)); do
echo -n ", T$(($n))"
done
echo -n ").Type, context: PostgresDecodingContext<JSONDecoder>, file: String = #fileID, line: Int = #line) "
echo -n "-> AsyncThrowingMapSequence<Self, (T0"
for ((n = 1; n<$how_many; n +=1)); do
echo -n ", T$(($n))"
done
echo ")> {"
echo " self.map { row in"
if [[ $how_many -eq 1 ]] ; then
echo " try row.decode(T0.self, context: context, file: file, line: line)"
else
echo -n " try row.decode((T0"
for ((n = 1; n<$how_many; n +=1)); do
echo -n ", T$n"
done
echo ").self, context: context, file: file, line: line)"
fi
echo " }"
echo " }"
}
function genWithoutContextParameter() {
how_many=$1
echo ""
echo " @inlinable"
echo " @_alwaysEmitIntoClient"
echo -n " public func decode<T0: PostgresDecodable"
for ((n = 1; n<$how_many; n +=1)); do
echo -n ", T$(($n)): PostgresDecodable"
done
echo -n ">(_: (T0"
for ((n = 1; n<$how_many; n +=1)); do
echo -n ", T$(($n))"
done
echo -n ").Type, file: String = #fileID, line: Int = #line) "
echo -n "-> AsyncThrowingMapSequence<Self, (T0"
for ((n = 1; n<$how_many; n +=1)); do
echo -n ", T$(($n))"
done
echo ")> {"
echo -n " self.decode("
if [[ $how_many -eq 1 ]] ; then
echo -n "T0.self"
else
echo -n "(T0"
for ((n = 1; n<$how_many; n +=1)); do
echo -n ", T$(($n))"
done
echo -n ").self"
fi
echo ", context: .default, file: file, line: line)"
echo " }"
}
grep -q "ByteBuffer" "${BASH_SOURCE[0]}" || {
echo >&2 "ERROR: ${BASH_SOURCE[0]}: file or directory not found (this should be this script)"
exit 1
}
{
cat <<"EOF"
/// NOTE: THIS FILE IS AUTO-GENERATED BY dev/generate-postgresrowsequence-multi-decode.sh
EOF
echo
echo "#if canImport(_Concurrency)"
echo "extension AsyncSequence where Element == PostgresRow {"
# note:
# - widening the inverval below (eg. going from {1..15} to {1..25}) is Semver minor
# - narrowing the interval below is SemVer _MAJOR_!
for n in {1..15}; do
genWithContextParameter "$n"
genWithoutContextParameter "$n"
done
echo "}"
echo "#endif"
} > "$here/../Sources/PostgresNIO/New/PostgresRowSequence-multi-decode.swift"