feat: add plpgsql-parser package for combined SQL + PL/pgSQL parsing #255
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.
feat: add plpgsql-parser package for combined SQL + PL/pgSQL parsing
Summary
Adds a new
plpgsql-parserpackage that provides a unified API for parsing SQL scripts containing PL/pgSQL functions. The package combines the SQL parser and PL/pgSQL parser, automatically detecting and hydrating PL/pgSQL function bodies.Key features:
parse(sql)- Auto-detectsCREATE FUNCTIONstatements withLANGUAGE plpgsqland hydrates themtransform(sql, callback)- Pipeline for parse → modify → deparse workflowsdeparseSync(parsed)- Converts modified AST back to SQL with pretty printingparseSql,parsePlpgsqlBody,deparseSql, etc.) for power usersUpdates since last revision
README.mdwith pretty headers (logo, CI badge, license badge, version badge) to matchplpgsql-deparserstylepgsql-parser,plpgsql-deparser)Review & Testing Checklist for Human
workspace:*forpgsql-deparserandplpgsql-deparser. Confirm the publish pipeline rewrites these to actual version numbers.CREATE FUNCTIONstatements.anytype usage -PlpgsqlFunctionData.hydratedis typed asany(types.ts:15). Consider if stronger typing is needed for downstream consumers.transform()function - OnlytransformSyncis tested; the async variant should be verified manually.extractFunctionInfosilently returnsnullon parse errors (parse.ts:90-92). Confirm this behavior is acceptable vs surfacing errors.Recommended test plan:
npm testinpackages/plpgsql-parser- all 7 tests should passnpm run buildand verify dist output looks correctNotes
@libpg-query/parser,pgsql-deparser,plpgsql-deparser)deparseSyncfunction usesrequire()inside the function body (deparse.ts:85) to avoid import conflicts - this is intentional but worth noting