diff --git a/core/database.php b/core/database.php index bd135c2d..ea3ac36f 100644 --- a/core/database.php +++ b/core/database.php @@ -169,6 +169,11 @@ class Database $this->engine->set_timeout($this->db, $time); } + public function notify(string $channel, ?string $data=null): void + { + $this->engine->notify($this->db, $channel, $data); + } + public function execute(string $query, array $args = []): PDOStatement { try { diff --git a/core/dbengine.php b/core/dbengine.php index 66be9d2b..638da437 100644 --- a/core/dbengine.php +++ b/core/dbengine.php @@ -33,6 +33,8 @@ abstract class DBEngine abstract public function set_timeout(PDO $db, int $time); abstract public function get_version(PDO $db): string; + + abstract public function notify(PDO $db, string $channel, ?string $data=null): void; } class MySQL extends DBEngine @@ -71,6 +73,10 @@ class MySQL extends DBEngine // $db->exec("SET SESSION MAX_EXECUTION_TIME=".$time.";"); } + public function notify(PDO $db, string $channel, ?string $data=null): void + { + } + public function get_version(PDO $db): string { return $db->query('select version()')->fetch()[0]; @@ -118,6 +124,15 @@ class PostgreSQL extends DBEngine $db->exec("SET statement_timeout TO ".$time.";"); } + public function notify(PDO $db, string $channel, ?string $data=null): void + { + if ($data) { + $db->exec("NOTIFY $channel, '$data';"); + } else { + $db->exec("NOTIFY $channel;"); + } + } + public function get_version(PDO $db): string { return $db->query('select version()')->fetch()[0]; @@ -229,6 +244,10 @@ class SQLite extends DBEngine // There doesn't seem to be such a thing for SQLite, so it does nothing } + public function notify(PDO $db, string $channel, ?string $data=null): void + { + } + public function get_version(PDO $db): string { return $db->query('select sqlite_version()')->fetch()[0];