forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-postgresrowsequence-multi-decode.sh
executable file
·73 lines (57 loc) · 1.84 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
#!/bin/bash
set -eu
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function gen() {
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 = #file, line: Int = #line) "
echo -n "-> AsyncThrowingMapSequence<PostgresRowSequence, (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 " }"
}
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 swift(>=5.5) && canImport(_Concurrency)"
echo "extension PostgresRowSequence {"
# 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
gen "$n"
done
echo "}"
echo "#endif"
} > "$here/../Sources/PostgresNIO/New/PostgresRowSequence-multi-decode.swift"