Skip to content

feat: implement routine_management RPC methods (#84) - #103

Merged
aesslinger merged 2 commits into
mainfrom
fix/84-routine-management
Sep 16, 2026
Merged

aesslinger merged 2 commits into
mainfrom
fix/84-routine-management

Conversation

@aesslinger

Copy link
Copy Markdown
Collaborator

Summary

  • Ports the builtin driver's PostgreSQL-dialect routine SQL builders (src-tauri/src/drivers/postgres/routines.rs) into a new src/handlers/routines.rs, and wires build_routine_call_sql, routine_create_template, drop_routine into the RPC dispatch table.
  • Previously all three hit the not_implemented catch-all, so the host silently fell back to generic, non-PostgreSQL SQL — invalid call syntax for functions with OUT params, a template with no LANGUAGE plpgsql/$$ dollar quoting, and a bare DROP FUNCTION name with no signature that can't disambiguate overloads.
  • routine_call_sql: SELECT * FROM fn(...) for functions (excludes pure OUT args, which PostgreSQL rejects in a function's call signature), CALL proc(...) for procedures (OUT args rendered as NULL placeholders, INOUT values echoed back by the server).
  • routine_create_template: valid, re-runnable CREATE OR REPLACE FUNCTION/PROCEDURE ... LANGUAGE plpgsql AS $$ ... $$ scripts.
  • drop_routine: resolves the routine's exact identity signature via pg_get_function_identity_arguments first, so an overloaded routine errors with a clear message instead of an ambiguous or wrong drop.

get_routine_edit_script is intentionally left alone — both the builtin and the host's plugin-bridge fallback already resolve it to get_routine_definition, which this plugin implements (per the issue's own note that this one isn't a gap).

Fixes #84.

Test plan

  • cargo test --lib — 309 passed (11 new unit tests in routines_tests.rs, matching the builtin's own routine_management test module's expected outputs byte-for-byte)
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • Confirmed the pre-fix binary returns Method not found (-32601) for all three methods against a live PostgreSQL instance, then confirmed the fix's binary returns correct results for the same requests
  • Live end-to-end verification — not just string-shape checks, actually executed the generated SQL:
    • build_routine_call_sql for a function with OUT params generates SELECT * FROM "public"."fn_split"(5);, which executes and returns the correct OUT values
    • build_routine_call_sql for a procedure with an OUT param generates CALL "public"."sp_greet"('world', NULL);, which executes and returns the correct result
    • routine_create_template for both FUNCTION and PROCEDURE produces scripts that execute successfully and create a routine that then runs correctly when called
    • drop_routine on an overloaded function returns a clear "has N overloads" error and drops neither overload; on a non-overloaded function it drops cleanly; on a missing routine it returns a clear "not found" error

Ports the builtin driver's PostgreSQL-dialect routine SQL builders into a
new src/handlers/routines.rs and wires build_routine_call_sql,
routine_create_template, and drop_routine into the RPC dispatch table.
Previously these three hit the not_implemented catch-all and the host
silently fell back to generic, non-PostgreSQL SQL: invalid function-call
syntax for OUT parameters, a template with no LANGUAGE plpgsql/$$ dollar
quoting, and a bare DROP FUNCTION with no signature that can't
disambiguate overloads.

- routine_call_sql: SELECT * FROM fn(...) for functions (excluding pure
  OUT args, which PostgreSQL rejects in a function's call signature),
  CALL proc(...) for procedures (OUT args rendered as NULL placeholders).
- routine_create_template: valid, re-runnable CREATE OR REPLACE
  FUNCTION/PROCEDURE ... LANGUAGE plpgsql AS $$ ... $$ scripts.
- drop_routine: resolves the routine's exact identity signature via
  pg_get_function_identity_arguments first, so overloaded routines error
  with a clear message instead of an ambiguous/wrong drop.

get_routine_edit_script is intentionally left alone — both the builtin and
the host's plugin-bridge fallback already resolve it to
get_routine_definition, which this plugin implements.

Verified live against a real PostgreSQL instance: confirmed the pre-fix
binary returns "Method not found" for all three methods, confirmed the
fix's generated SQL round-trips correctly by actually executing it
(a function with OUT params, a procedure with an OUT param, both
templates including running the routine they create), and confirmed
drop_routine refuses an overloaded function while dropping a
non-overloaded one cleanly.
@aesslinger aesslinger added the prerelease:rc Version suggestion targets a release candidate label Sep 16, 2026
@github-actions

Copy link
Copy Markdown

Version suggestion

Based on this PR's title (feat) and the prerelease:rc label:

Current 1.0.0-rc.3
Suggested next tag v1.0.0-rc.4

This is informational only — no tag or release is created automatically yet.

@aesslinger aesslinger self-assigned this Sep 16, 2026
@aesslinger
aesslinger merged commit e66ad88 into main Sep 16, 2026
7 checks passed
@aesslinger
aesslinger deleted the fix/84-routine-management branch September 16, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prerelease:rc Version suggestion targets a release candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Routine management: build_routine_call_sql / routine_create_template / drop_routine unimplemented despite routine_management capability

1 participant