feat: implement routine_management RPC methods (#84) - #103
Merged
Merged
Conversation
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.
Version suggestionBased on this PR's title (
This is informational only — no tag or release is created automatically yet. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src-tauri/src/drivers/postgres/routines.rs) into a newsrc/handlers/routines.rs, and wiresbuild_routine_call_sql,routine_create_template,drop_routineinto the RPC dispatch table.not_implementedcatch-all, so the host silently fell back to generic, non-PostgreSQL SQL — invalid call syntax for functions withOUTparams, a template with noLANGUAGE plpgsql/$$dollar quoting, and a bareDROP FUNCTION namewith no signature that can't disambiguate overloads.routine_call_sql:SELECT * FROM fn(...)for functions (excludes pureOUTargs, which PostgreSQL rejects in a function's call signature),CALL proc(...)for procedures (OUTargs rendered asNULLplaceholders,INOUTvalues echoed back by the server).routine_create_template: valid, re-runnableCREATE OR REPLACE FUNCTION/PROCEDURE ... LANGUAGE plpgsql AS $$ ... $$scripts.drop_routine: resolves the routine's exact identity signature viapg_get_function_identity_argumentsfirst, so an overloaded routine errors with a clear message instead of an ambiguous or wrong drop.get_routine_edit_scriptis intentionally left alone — both the builtin and the host's plugin-bridge fallback already resolve it toget_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 inroutines_tests.rs, matching the builtin's ownroutine_managementtest module's expected outputs byte-for-byte)cargo clippy --all-targets -- -D warnings— cleancargo fmt --all -- --check— cleanMethod not found (-32601)for all three methods against a live PostgreSQL instance, then confirmed the fix's binary returns correct results for the same requestsbuild_routine_call_sqlfor a function withOUTparams generatesSELECT * FROM "public"."fn_split"(5);, which executes and returns the correctOUTvaluesbuild_routine_call_sqlfor a procedure with anOUTparam generatesCALL "public"."sp_greet"('world', NULL);, which executes and returns the correct resultroutine_create_templatefor both FUNCTION and PROCEDURE produces scripts that execute successfully and create a routine that then runs correctly when calleddrop_routineon 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