pgFormatter icon indicating copy to clipboard operation
pgFormatter copied to clipboard

Ability to work in streaming mode

Open bogdan opened this issue 1 year ago • 4 comments

The binary always waits for the STDIN to be closed and than formats all supplied sql:

$  pg_format -
select * from companies;
select * from companies;
Ctrl+D
SELECT
    *
FROM
    companies;

SELECT
    *
FROM
    companies;

This restricts the ability to work in streaming mode. Is it possible to format one SQL statement as long as it finishes (e.g. by ;)? cat can be used as example as it triggers output on each line break

bogdan avatar Mar 05 '24 10:03 bogdan

Hi,

If you want to format a query in interactive mode you must use the following:

echo "select * from companies;" | pg_format -

and call pg_format - each time you want to format e new query.

I agree that this is not convenient for streaming mode. I will see if there is a simple way to allow that.

darold avatar Mar 06 '24 11:03 darold

This could be handled using the Perl module Term::ReadLine but I'm not sure it could be helpful to have such feature. What is your use case for this feature?

darold avatar Mar 06 '24 13:03 darold

I am calling pg_format executive from ruby program. It takes ~200ms to do, which is way too slow. If I can keep a running process in memory and interact with it through stdin and stdout (which what any programming language probably allows), the indent can be much faster.

bogdan avatar Mar 06 '24 18:03 bogdan

Maybe use the Record Separator ASCII/Unicode symbol? It’s 0x1E in Utf-8

Profpatsch avatar May 13 '24 09:05 Profpatsch