Expose C++ API interface
robertrossmann opened this issue · 3 comments
It would be a great feature to implement some kind of programmatic API to check an SQL file (either from path or from the contents given as argument) so that 3rd party tools can be built around sqlcheck.
My primary interest is to integrate this tool into an editor/IDE for SQL file linting. Currently the only way to integrate this tool into an editor would be to run shellcheck
as a standard command invocation from shell and parse the output, then map it to the lines and character positions. This approach is not very performant and would require a lot of work, especially in the output parsing logic. However, creating a stanard way to programmatically invoke shellcheck would work perfectly for this use case.
Unfortunately I am not proficient enough in C/C++ to send a PR, so leaving this here as a suggestion only. Thank you for considering this feature!
@robertrossmann Thanks for the feedback! This tool actually is a wrapper around a C++ library (sqlcheck_library
) that exposes a programmatic API to check an SQL file. You can integrate the sqlcheck_library
into an editor.
https://github.com/jarulraj/sqlcheck/blob/master/src/CMakeLists.txt#L13
https://github.com/jarulraj/sqlcheck/blob/master/src/CMakeLists.txt#L17
Thanks @jarulraj for your tip! I would definitely use that function to integrate this tool into an editor, however what worries me is that function's output - it's just stdout
! This makes mapping the results back to the code in the editor rather difficult.
The optimal interface of that function would be that I give it a string with the SQL and it gives me back some data structure (ie. an array?) with the errors and their position in the string. This way I could format the results for display in any way I need. I could even show a marker in the editor.
This will most likely be a non-trivial task should you decide to adopt it. However, I would be ever so grateful! Thanks!
I see, that's a helpful suggestion. I think that it should not be too hard.
I will give it a shot in the near future!