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

Commit 957c87e

Browse files
author
Dominik František Bučík
committed
feat: 🎸 Make methods for reading DB public
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)
1 parent e28d4ac commit 957c87e

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

lib/DatabaseCommand.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,34 @@ public function aggregate()
242242
}
243243
}
244244

245+
public function read($query, $params): PDOStatement
246+
{
247+
return $this->conn->read($query, $params);
248+
}
249+
250+
public function isPgsql(): bool
251+
{
252+
return $this->conn->getDriver() === 'pgsql';
253+
}
254+
255+
public function isMysql(): bool
256+
{
257+
return $this->conn->getDriver() === 'mysql';
258+
}
259+
260+
public function escapeCol($col_name): string
261+
{
262+
return $this->escape_char . $col_name . $this->escape_char;
263+
}
264+
265+
public function escapeCols($col_names): string
266+
{
267+
return $this->escape_char . implode(
268+
$this->escape_char . ',' . $this->escape_char,
269+
$col_names
270+
) . $this->escape_char;
271+
}
272+
245273
private function insertLogin($entities, $userId, $date)
246274
{
247275
foreach (Config::SIDES as $side) {
@@ -265,11 +293,6 @@ private function insertLogin($entities, $userId, $date)
265293
}
266294
}
267295

268-
private function escapeCol($col_name): string
269-
{
270-
return $this->escape_char . $col_name . $this->escape_char;
271-
}
272-
273296
private function writeLogin($date, $ids, $user): bool
274297
{
275298
if (empty($user)) {
@@ -475,14 +498,6 @@ private function prependColon($str): string
475498
return ':' . $str;
476499
}
477500

478-
private function escapeCols($col_names): string
479-
{
480-
return $this->escape_char . implode(
481-
$this->escape_char . ',' . $this->escape_char,
482-
$col_names
483-
) . $this->escape_char;
484-
}
485-
486501
private function getAggregateGroupBy($ids): string
487502
{
488503
$columns = ['day'];
@@ -532,21 +547,6 @@ private function getSpName($request)
532547
return $displayName;
533548
}
534549

535-
private function read($query, $params): PDOStatement
536-
{
537-
return $this->conn->read($query, $params);
538-
}
539-
540-
private function isPgsql(): bool
541-
{
542-
return $this->conn->getDriver() === 'pgsql';
543-
}
544-
545-
private function isMysql(): bool
546-
{
547-
return $this->conn->getDriver() === 'mysql';
548-
}
549-
550550
private function unknownDriver()
551551
{
552552
Logger::error(self::DEBUG_PREFIX . 'unsupported DB driver \'' . $this->conn->getDriver());

0 commit comments

Comments
 (0)