Skip to content

use dbgate-query-splitter lib to split queries#119

Merged
debba merged 3 commits intodebba:mainfrom
dev-void-7:fix/split-queries-issues
Apr 8, 2026
Merged

use dbgate-query-splitter lib to split queries#119
debba merged 3 commits intodebba:mainfrom
dev-void-7:fix/split-queries-issues

Conversation

@dev-void-7
Copy link
Copy Markdown
Contributor

The Issue

the function splitQueries works for normal SQL like SELECT, UPDATE, ...etc. But, when it comes to SQL like creating a function or stored procedure it fails to split properly like the following example:

CREATE FUNCTION example()
RETURNS INT
LANGUAGE PLPGSQL
AS $$
BEGIN
    RETURN 10::INT;
END;
$$;

The Fix

inside splitQueries function in utils module call splitQuery function from dbgate-query-splitter library to handle the splitting.

Issues That Still Exist

Due to slight difference in syntax between DBMS SplitQuery function accespts an optional second parameter which is SplitterOptions. each DBMS has own unique options that make splitting differs.

To solve we need to pass the database name to the splitQueries function so the we can determine which options to pass to splitQuery function. Unfortunately, I can only work with Vue, Svelte, or TypeScript, not React, and because this solution requires modifying code within React files, I couldn't implement it :(

@kilo-code-bot
Copy link
Copy Markdown

kilo-code-bot bot commented Apr 7, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • package.json - Added dependency dbgate-query-splitter@^4.12.0
  • pnpm-lock.yaml - Lock file updates (auto-generated)
  • src/utils/sql.ts - Replaced custom SQL splitter with library implementation
Change Summary

The PR replaces a custom 67-line SQL query splitter with a call to the dbgate-query-splitter library using postgreSplitterOptions.

Benefits of this change:

  • Properly handles complex SQL like CREATE FUNCTION with PL/pgSQL blocks
  • Correctly handles semicolons inside string literals and comments
  • Reduced maintenance burden (60+ lines removed)
  • Well-tested library used by the dbgate project

Note: The current implementation uses PostgreSQL-specific options for all database types. The PR author acknowledges this limitation and notes that passing the database type to select appropriate splitter options would be a future enhancement.


Reviewed by kimi-k2.5 · 98,891 tokens

@debba
Copy link
Copy Markdown
Owner

debba commented Apr 7, 2026

Hi!
Very interesting, need to find a solution for external drivers.
I will take a look ASAP

@dev-void-7
Copy link
Copy Markdown
Contributor Author

i don't know how external drivers are managed but anyway the current solution still handle all old cases with extra support for postgres syntax (i set the options of SplitQuery to the one that aligns with postgres).

in fact i use PgManage and one of the things that prevents me to fully depend on tabularis is this problem (the problem of not being able to create postgres functions).

what do you think:

  • apply these changes then work on the external drivers and other drivers special syntax later OR.
  • work on the external drivers and other drivers special syntax first then merge

My Best Regards :)

@debba debba merged commit 60008e9 into debba:main Apr 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants