finish migration class

This commit is contained in:
Jan-Niclas Loosen
2025-02-12 16:55:03 +01:00
parent c4a7025978
commit fe9661d611
5 changed files with 196 additions and 148 deletions

View File

@@ -75,26 +75,26 @@ class Query
// Build the SELECT clause.
$columns = implode(", ", $selectColumns);
$primaryTable = $this->schema->name;
$sqlStatement = "SELECT $columns FROM $primaryTable";
$query = "SELECT $columns FROM $primaryTable";
// Append join clauses, if any.
if ($this->isJoined())
foreach ($this->joins as $join)
$sqlStatement .= " " . $join['type']->toString() . " NATURAL JOIN " . $join['table'];
$query .= " " . $join['type']->toString() . " NATURAL JOIN " . $join['table'];
// Append the WHERE clause if conditions exist.
if ($this->isConditioned()) {
$whereClause = $this->combineConditions();
$sqlStatement .= " WHERE $whereClause";
$query .= " WHERE $whereClause";
}
// Append the ORDER BY clause if ordering is set.
if ($this->isOrdered()) {
$orderClause = $this->orderBy['name'] . ' ' . $this->orderBy['order'];
$sqlStatement .= " ORDER BY $orderClause";
$query .= " ORDER BY $orderClause";
}
return esc_sql($sqlStatement);
return $query;
}
public function aggregate(string $col, string $alias, Aggregation $func): Query {