Skip to content

Commit 92d373f

Browse files
authored
feat: support multiple --url arguments with per-URL format and headers (#211)
1 parent 73b1b03 commit 92d373f

7 files changed

Lines changed: 301 additions & 98 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,13 @@ jobs:
653653
# binaries, man page, .deb, .rpm AND .nupkg packages.
654654
checksums:
655655
name: Generate SHA256 checksums
656-
needs: [release, package-deb, package-rpm, package-apk, package-choco]
656+
needs: [release, package-deb, package-rpm, package-apk]
657657
if: >-
658658
always()
659659
&& needs.release.result == 'success'
660660
&& (needs.package-deb.result == 'success' || needs.package-deb.result == 'skipped')
661661
&& (needs.package-rpm.result == 'success' || needs.package-rpm.result == 'skipped')
662662
&& (needs.package-apk.result == 'success' || needs.package-apk.result == 'skipped')
663-
&& (needs.package-choco.result == 'success' || needs.package-choco.result == 'skipped')
664663
runs-on: ubuntu-latest
665664
permissions:
666665
contents: write

‎build.zig‎

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,30 +225,54 @@ pub fn build(b: *std.Build) void {
225225
\\[ -s "$port_file" ]
226226
\\base="http://127.0.0.1:$(cat "$port_file")"
227227
\\bin=./zig-out/bin/sql-pipe
228-
\\[ "$("$bin" --url "$base/csv" 'SELECT name FROM t')" = Ada ]
229-
\\[ "$("$bin" --url "$base/json" 'SELECT name FROM t')" = Ada ]
230-
\\[ "$("$bin" --url "$base/fallback.csv" 'SELECT name FROM t')" = Ada ]
231-
\\[ "$("$bin" --url "$base/override" -I json 'SELECT name FROM t')" = Ada ]
232-
\\[ "$("$bin" --url "$base/headers" --http-header 'X-Test: one' --http-header 'X-Other: two' 'SELECT name FROM t')" = Ada ]
233-
\\[ "$("$bin" --url "$base/redirect" 'SELECT name FROM t')" = Ada ]
228+
\\[ "$("$bin" --url "$base/csv" 'SELECT name FROM url0')" = Ada ]
229+
\\[ "$("$bin" --url "$base/json" -I json 'SELECT name FROM url0')" = Ada ]
230+
\\[ "$("$bin" --url "$base/fallback.csv" 'SELECT name FROM url0')" = Ada ]
231+
\\[ "$("$bin" --url "$base/override" -I json 'SELECT name FROM url0')" = Ada ]
232+
\\[ "$("$bin" --url "$base/headers" --http-header 'X-Test: one' --http-header 'X-Other: two' 'SELECT name FROM url0')" = Ada ]
233+
\\[ "$("$bin" --url "$base/redirect" 'SELECT name FROM url0')" = Ada ]
234234
\\! "$bin" --url "$base/redirect-with-header" --http-header 'X-Test: one' 'SELECT 1' >/dev/null 2>"$err_file"
235235
\\grep -q 'failed to fetch URL' "$err_file"
236-
\\[ "$("$bin" --url "$base/hits" 'SELECT hits FROM t')" = 0 ]
237-
\\[ "$("$bin" --url "$base/redirect-chain/5" 'SELECT name FROM t')" = Ada ]
236+
\\[ "$("$bin" --url "$base/hits" 'SELECT hits FROM url0')" = 0 ]
237+
\\[ "$("$bin" --url "$base/redirect-chain/5" 'SELECT name FROM url0')" = Ada ]
238238
\\! "$bin" --url "$base/redirect-chain/6" 'SELECT 1' >/dev/null 2>"$err_file"
239239
\\grep -q 'failed to fetch URL' "$err_file"
240240
\\! "$bin" --url "$base/missing" 'SELECT 1' >/dev/null 2>"$err_file"
241241
\\grep -q "failed to fetch URL: $base/missing (HTTP 404)" "$err_file"
242-
\\[ "$("$bin" --url "$base/empty" 'SELECT count(*) FROM t')" = 0 ]
242+
\\[ "$("$bin" --url "$base/empty" 'SELECT count(*) FROM url0')" = 0 ]
243243
\\! "$bin" --url "$base/large" --max-body-size 8 'SELECT 1' >/dev/null 2>"$err_file"
244244
\\grep -q 'failed to fetch URL' "$err_file"
245-
\\join_query='SELECT t.name, customers.name FROM t JOIN customers ON t.id = customers.id'
245+
\\join_query='SELECT url0.name, customers.name FROM url0 JOIN customers ON url0.id = customers.id'
246246
\\printf 'id,name\n99,Wrong\n' | "$bin" --url "$base/csv" tests/fixtures/customers.csv "$join_query" | diff - <(printf 'Ada,Alice\n')
247247
});
248248
test_http_input.addArtifactArg(http_server);
249249
test_http_input.step.dependOn(b.getInstallStep());
250250
test_step.dependOn(&test_http_input.step);
251251

252+
// Integration test 3b: per-URL --input-format and --http-header
253+
const test_per_url_flags = b.addSystemCommand(&.{
254+
"bash", "-c",
255+
\\set -euo pipefail
256+
\\server="$0"
257+
\\port_file=$(mktemp)
258+
\\rm -f "$port_file"
259+
\\"$server" "$port_file" & server_pid=$!
260+
\\cleanup() { kill "$server_pid" 2>/dev/null || true; wait "$server_pid" 2>/dev/null || true; rm -f "$port_file"; }
261+
\\trap cleanup EXIT
262+
\\for _ in $(seq 1 100); do [ -s "$port_file" ] && break; sleep 0.05; done
263+
\\[ -s "$port_file" ]
264+
\\base="http://127.0.0.1:$(cat "$port_file")"
265+
\\bin=./zig-out/bin/sql-pipe
266+
\\# Per-URL format: URL1 gets json (auto-detect), URL2 gets csv
267+
\\[ "$("$bin" --url "$base/json" --input-format json --url "$base/csv" 'SELECT url0.name FROM url0')" = Ada ]
268+
\\# Per-URL headers: headers apply to preceding URL only
269+
\\[ "$("$bin" --url "$base/csv" --http-header "X-Test: one" 'SELECT name FROM url0')" = Ada ]
270+
\\echo "per-url-flags: OK"
271+
});
272+
test_per_url_flags.addArtifactArg(http_server);
273+
test_per_url_flags.step.dependOn(b.getInstallStep());
274+
test_step.dependOn(&test_per_url_flags.step);
275+
252276
// Integration test 4: --help flag prints usage to stderr and exits 0
253277
const test_help = b.addSystemCommand(&.{
254278
"bash", "-c",
@@ -1766,7 +1790,7 @@ pub fn build(b: *std.Build) void {
17661790
\\dir=$(mktemp -d)
17671791
\\printf 'uid,name\n1,Alice\n2,Bob\n' > "$dir/users.csv"
17681792
\\result=$(printf 'user_id,amount\n1,150\n2,80\n' \
1769-
\\ | ./zig-out/bin/sql-pipe "$dir/users.csv" 'SELECT t.amount, u.name FROM t JOIN users u ON t.user_id = u.uid ORDER BY u.name')
1793+
\\ | ./zig-out/bin/sql-pipe "$dir/users.csv" 'SELECT stdin.amount, u.name FROM stdin JOIN users u ON stdin.user_id = u.uid ORDER BY u.name')
17701794
\\rm -rf "$dir"
17711795
\\[ "$result" = "$(printf '150,Alice\n80,Bob')" ]
17721796
});
@@ -1837,12 +1861,12 @@ pub fn build(b: *std.Build) void {
18371861
test_file_no_input.step.dependOn(b.getInstallStep());
18381862
test_step.dependOn(&test_file_no_input.step);
18391863

1840-
// Integration test 155j: File named t.csv conflicts with stdin table t
1864+
// Integration test 155j: File named stdin.csv conflicts with stdin table stdin
18411865
const test_file_t_conflict = b.addSystemCommand(&.{
18421866
"bash", "-c",
18431867
\\dir=$(mktemp -d)
1844-
\\printf 'a,b\n1,2\n' > "$dir/t.csv"
1845-
\\msg=$(printf 'x,y\n3,4\n' | ./zig-out/bin/sql-pipe "$dir/t.csv" 'SELECT * FROM t' 2>&1 >/dev/null; echo "EXIT:$?")
1868+
\\printf 'a,b\n1,2\n' > "$dir/stdin.csv"
1869+
\\msg=$(printf 'x,y\n3,4\n' | ./zig-out/bin/sql-pipe "$dir/stdin.csv" 'SELECT * FROM stdin' 2>&1 >/dev/null; echo "EXIT:$?")
18461870
\\rm -rf "$dir"
18471871
\\echo "$msg" | grep -q 'duplicate table name' && echo "$msg" | grep -q 'EXIT:1'
18481872
});

0 commit comments

Comments
 (0)