forked from Cavemanon/cavepaintings
database notification API
This commit is contained in:
@ -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];
|
||||
|
Reference in New Issue
Block a user