Skip to content

Commit 4946886

Browse files
committed
Prettier SQL formatting
1 parent 2e5391b commit 4946886

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/PHPFUI/ORM/Table.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,15 @@ public function getGroupBy() : string
416416
}
417417

418418
$comma = '';
419-
$retVal = ' GROUP BY';
419+
$retVal = "\nGROUP BY";
420420
$addRollup = 0;
421421

422422
foreach ($this->groupBys as $field => $rollup)
423423
{
424424
$parts = \explode('.', $field);
425425
$field = \implode('`.`', $parts);
426426
$retVal .= "{$comma} `{$field}`";
427-
$comma = ',';
427+
$comma = ",\n";
428428

429429
$addRollup |= (int)$rollup;
430430
}
@@ -453,7 +453,7 @@ public function getHaving(array &$input) : string
453453

454454
$input = \array_merge($input, $this->havingCondition->getInput());
455455

456-
return ' HAVING ' . $this->havingCondition;
456+
return "\nHAVING " . $this->havingCondition;
457457
}
458458

459459
public function getHavingCondition() : \PHPFUI\ORM\Condition
@@ -495,7 +495,7 @@ public function getLimitClause() : string
495495
// could just be a string, return it
496496
if ($this->limit && ! $this->offset && null === $this->page)
497497
{
498-
return ' LIMIT ' . $this->limit;
498+
return "\nLIMIT {$this->limit}";
499499
}
500500

501501
if (! $this->limit)
@@ -515,7 +515,7 @@ public function getLimitClause() : string
515515
}
516516
$this->offset = $offset;
517517

518-
return " LIMIT {$offset}, {$this->limit}";
518+
return "\nLIMIT {$offset}, {$this->limit}";
519519
}
520520

521521
public function getOffset() : ?int
@@ -534,7 +534,7 @@ public function getOrderBy() : string
534534
}
535535

536536
$comma = '';
537-
$retVal = ' ORDER BY';
537+
$retVal = "\nORDER BY";
538538

539539
foreach ($this->orderBys as $field => $direction)
540540
{
@@ -607,7 +607,7 @@ public function getSelect() : string
607607

608608
$columns = [];
609609
// make explicit column names for joined tables since we don't have explicit selects
610-
$sql = "`{$this->instance->getTableName()}`.*";
610+
$sql = "\n`{$this->instance->getTableName()}`.*";
611611
// set column names from explicit select
612612
foreach ($this->getFields() as $field => $data)
613613
{
@@ -625,11 +625,11 @@ public function getSelect() : string
625625
{
626626
if (isset($columns[$field]))
627627
{
628-
$sql .= ",`{$tableName}`.`{$field}` as `{$tableName}_{$field}`";
628+
$sql .= ",\n`{$tableName}`.`{$field}` as `{$tableName}_{$field}`";
629629
}
630630
else
631631
{
632-
$sql .= ",`{$tableName}`.`{$field}`";
632+
$sql .= ",\n`{$tableName}`.`{$field}`";
633633
$columns[$field] = true;
634634
}
635635
}
@@ -639,7 +639,7 @@ public function getSelect() : string
639639
{
640640
return $sql;
641641
}
642-
$comma = ',';
642+
$comma = ",\n";
643643
}
644644

645645
foreach ($this->selects as $field => $as)
@@ -650,7 +650,7 @@ public function getSelect() : string
650650
{
651651
$sql .= ' as `' . $as . '`';
652652
}
653-
$comma = ',';
653+
$comma = ",\n";
654654
}
655655
$sql = \str_replace('`*`', '*', $sql);
656656

@@ -672,7 +672,7 @@ public function getSQL(array &$input, bool $limited = true) : string
672672
$having = $this->getHaving($input);
673673
$orderBy = $this->getOrderBy();
674674
$limit = $this->getLimitClause();
675-
$sql = "SELECT {$this->distinct} {$select} FROM `{$table}`" . $joins . $where . $groupBy . $having;
675+
$sql = "SELECT {$this->distinct} {$select}\nFROM `{$table}`" . $joins . $where . $groupBy . $having;
676676

677677
if ($this->unions)
678678
{
@@ -719,7 +719,7 @@ public function getWhere(array &$input) : string
719719

720720
$input = \array_merge($input, $this->whereCondition->getInput());
721721

722-
return ' WHERE ' . $this->whereCondition;
722+
return "\nWHERE " . $this->whereCondition;
723723
}
724724

725725
public function getWhereCondition() : \PHPFUI\ORM\Condition
@@ -752,7 +752,7 @@ public function insert(array $records, string $ignore = '') : bool
752752
foreach ($fields as $fieldName)
753753
{
754754
$sql .= "{$comma}`{$fieldName}`";
755-
$comma = ',';
755+
$comma = ",\n";
756756
}
757757

758758
$sql .= ') values ';
@@ -773,7 +773,7 @@ public function insert(array $records, string $ignore = '') : bool
773773
foreach ($fields as $fieldName)
774774
{
775775
$sql .= $comma . '?';
776-
$comma = ',';
776+
$comma = ",\n";
777777
$input[] = $record[$fieldName];
778778
}
779779
$comma = '),(';
@@ -965,7 +965,7 @@ public function update(array $variables) : static
965965
{
966966
$this->lastSql .= "{$comma} `{$field}`=?";
967967
$this->lastInput[] = $value;
968-
$comma = ',';
968+
$comma = ",\n";
969969
}
970970

971971
$where = $this->getWhere($this->lastInput);
@@ -1062,7 +1062,7 @@ private function getJoins(array &$input) : string
10621062
$onCondition = $joinInfo[1];
10631063
$joinType = $joinInfo[2];
10641064
$input = \array_merge($input, $onCondition->getInput());
1065-
$joins .= " {$joinType} JOIN `{$joinTableName}`{$as} ON {$onCondition}";
1065+
$joins .= "\n{$joinType} JOIN `{$joinTableName}`{$as} ON {$onCondition}";
10661066
}
10671067

10681068
return $joins;

0 commit comments

Comments
 (0)