Skip to content

Commit 5d699d9

Browse files
Merge pull request #19308 from kamil-tekiela/formatSingleLine
Implement Format in a single line Closes #17480
2 parents 2e77de9 + d05d6d5 commit 5d699d9

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

resources/js/src/sql.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ const insertQuery = function (queryType) {
263263
setQuery('');
264264

265265
return;
266-
} else if (queryType === 'format') {
266+
} else if (queryType === 'format' || queryType === 'formatSingleLine') {
267267
if (window.codeMirrorEditor) {
268268
$('#querymessage').html(window.Messages.strFormatting +
269269
'&nbsp;<img class="ajaxIcon" src="' +
@@ -272,7 +272,8 @@ const insertQuery = function (queryType) {
272272
var params = {
273273
'ajax_request': true,
274274
'sql': window.codeMirrorEditor.getValue(),
275-
'server': CommonParams.get('server')
275+
'server': CommonParams.get('server'),
276+
'formatSingleLine': queryType === 'formatSingleLine'
276277
};
277278
$.ajax({
278279
type: 'POST',

resources/templates/sql/query.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<input type="button" value="{{ t('Clear') }}" id="clear" class="btn btn-secondary button sqlbutton">
3939
{% if codemirror_enable %}
4040
<input type="button" value="{{ t('Format') }}" id="format" class="btn btn-secondary button sqlbutton">
41+
<input type="button" value="{{ t('Format as a single line') }}" id="formatSingleLine" class="btn btn-secondary button sqlbutton">
4142
{% endif %}
4243
</div>
4344

src/Controllers/Database/SqlFormatController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public function __invoke(ServerRequest $request): Response
2323
{
2424
/** @var string $query */
2525
$query = $request->getParsedBodyParam('sql', '');
26-
$this->response->addJSON(['sql' => Formatter::format($query)]);
26+
if ($request->getParsedBodyParam('formatSingleLine') === 'true') {
27+
$this->response->addJSON(['sql' => Formatter::format($query, ['line_ending' => ' ', 'indentation' => ''])]);
28+
} else {
29+
$this->response->addJSON(['sql' => Formatter::format($query)]);
30+
}
2731

2832
return $this->response->response();
2933
}

0 commit comments

Comments
 (0)