Use long line strings for big queries and start the connection abstracts.

This commit is contained in:
Dave Smith-Hayes 2024-07-21 21:33:34 -04:00
parent 7b64e688be
commit 7f05554f4e
4 changed files with 37 additions and 12 deletions

View File

@ -1,4 +1,4 @@
<?php
<?php /** @noinspection ALL */
namespace Slovocast\Domain\Repository\Channel;
@ -95,9 +95,11 @@ class ChannelRepository implements ChannelRepositoryInterface
*/
public function create(Channel $channel, User $owner): int
{
$query = "INSERT INTO channels (name, slug, description, link,
language, copyright, explicit, owner_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$query = <<<SQL
INSERT INTO channels (name, slug, description, link,
language, copyright, explicit, owner_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
SQL;
$results = await($this->db->query($query, [
$channel->getName(),
@ -120,13 +122,16 @@ class ChannelRepository implements ChannelRepositoryInterface
*/
public function update(Channel $channel): bool
{
$query = "UPDATE channels SET name = ?,
slug = ?,
description = ?,
link = ?,
language = ?,
copyright = ?,
explicit = ?";
$query = <<<SQL
UPDATE channels SET name = ?,
slug = ?,
description = ?,
link = ?,
language = ?,
copyright = ?,
explicit = ?
WHERE id = ?;
SQL;
$results = await($this->db->query($query, [
$channel->getName(),
@ -136,6 +141,7 @@ class ChannelRepository implements ChannelRepositoryInterface
$channel->getLanguage(),
$channel->getCopyright(),
$channel->isExplicit(),
$channel->getId(),
]));
return (bool) $results->affectedRows;

View File

@ -0,0 +1,8 @@
<?php
namespace Slovocast\Infrastructure\Api\Database;
interface ConnectionInterface
{
public function release(): void;
}

View File

@ -0,0 +1,11 @@
<?php
namespace Slovocast\Infrastructure\Api\Database;
interface ConnectionPoolInterface
{
public function getTotalConnectionCount(): int;
public function hasFreeConnection(): bool;
public function getConnection(): ConnectionInterface;
public function releaseConnection(ConnectionInterface $connection): void;
}

View File

@ -14,7 +14,7 @@ services:
- slovocast_db:/var/lib/mysql/data/
app:
build:
content: .
context: .
dockerfile: deploy/php/Dockerfile
ports:
- "8000:8000"