Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
feat: 🎸 Make methods for reading DB public
Browse files Browse the repository at this point in the history
make methods to read and related tasks for constructing read queries
public so other components can make use of it (i.e. external API that
needs to use custom query)
  • Loading branch information
Dominik František Bučík committed Aug 12, 2022
1 parent e28d4ac commit 957c87e
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions lib/DatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,34 @@ public function aggregate()
}
}

public function read($query, $params): PDOStatement
{
return $this->conn->read($query, $params);
}

public function isPgsql(): bool
{
return $this->conn->getDriver() === 'pgsql';
}

public function isMysql(): bool
{
return $this->conn->getDriver() === 'mysql';
}

public function escapeCol($col_name): string
{
return $this->escape_char . $col_name . $this->escape_char;
}

public function escapeCols($col_names): string
{
return $this->escape_char . implode(
$this->escape_char . ',' . $this->escape_char,
$col_names
) . $this->escape_char;
}

private function insertLogin($entities, $userId, $date)
{
foreach (Config::SIDES as $side) {
Expand All @@ -265,11 +293,6 @@ private function insertLogin($entities, $userId, $date)
}
}

private function escapeCol($col_name): string
{
return $this->escape_char . $col_name . $this->escape_char;
}

private function writeLogin($date, $ids, $user): bool
{
if (empty($user)) {
Expand Down Expand Up @@ -475,14 +498,6 @@ private function prependColon($str): string
return ':' . $str;
}

private function escapeCols($col_names): string
{
return $this->escape_char . implode(
$this->escape_char . ',' . $this->escape_char,
$col_names
) . $this->escape_char;
}

private function getAggregateGroupBy($ids): string
{
$columns = ['day'];
Expand Down Expand Up @@ -532,21 +547,6 @@ private function getSpName($request)
return $displayName;
}

private function read($query, $params): PDOStatement
{
return $this->conn->read($query, $params);
}

private function isPgsql(): bool
{
return $this->conn->getDriver() === 'pgsql';
}

private function isMysql(): bool
{
return $this->conn->getDriver() === 'mysql';
}

private function unknownDriver()
{
Logger::error(self::DEBUG_PREFIX . 'unsupported DB driver \'' . $this->conn->getDriver());
Expand Down

0 comments on commit 957c87e

Please sign in to comment.