From d05d6d55c5e348a1a39d76c83c818dcdc666a8f5 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 30 Sep 2024 15:13:13 +0100 Subject: [PATCH] Implement Format in a single line Signed-off-by: Kamil Tekiela --- resources/js/src/sql.ts | 5 +++-- resources/templates/sql/query.twig | 1 + src/Controllers/Database/SqlFormatController.php | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/resources/js/src/sql.ts b/resources/js/src/sql.ts index 10a10dc37c..6296e46a48 100644 --- a/resources/js/src/sql.ts +++ b/resources/js/src/sql.ts @@ -263,7 +263,7 @@ const insertQuery = function (queryType) { setQuery(''); return; - } else if (queryType === 'format') { + } else if (queryType === 'format' || queryType === 'formatSingleLine') { if (window.codeMirrorEditor) { $('#querymessage').html(window.Messages.strFormatting + '  {% if codemirror_enable %} + {% endif %} diff --git a/src/Controllers/Database/SqlFormatController.php b/src/Controllers/Database/SqlFormatController.php index 0d985b3939..7aa4f80dbe 100644 --- a/src/Controllers/Database/SqlFormatController.php +++ b/src/Controllers/Database/SqlFormatController.php @@ -23,7 +23,11 @@ final class SqlFormatController implements InvocableController { /** @var string $query */ $query = $request->getParsedBodyParam('sql', ''); - $this->response->addJSON(['sql' => Formatter::format($query)]); + if ($request->getParsedBodyParam('formatSingleLine') === 'true') { + $this->response->addJSON(['sql' => Formatter::format($query, ['line_ending' => ' ', 'indentation' => ''])]); + } else { + $this->response->addJSON(['sql' => Formatter::format($query)]); + } return $this->response->response(); }