mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-22 12:31:15 +01:00
Implement byteaA postgres migration
This commit is contained in:
parent
94706cb0a8
commit
de7676fc98
@ -61,7 +61,7 @@ final class DbPropertiesFactory
|
||||
$class .= '\\MysqlArray';
|
||||
break;
|
||||
case $dbSettings instanceof Postgres:
|
||||
$class .= '\\PostgresArrayBytea';
|
||||
$class .= '\\PostgresArray';
|
||||
break;
|
||||
case $dbSettings instanceof Redis:
|
||||
$class .= '\\RedisArray';
|
||||
|
@ -21,6 +21,44 @@ use danog\MadelineProto\Settings\Database\SerializerType;
|
||||
*/
|
||||
class PostgresArray extends PostgresArrayBytea
|
||||
{
|
||||
/**
|
||||
* Prepare statements.
|
||||
*
|
||||
* @param SqlArray::SQL_* $type
|
||||
*/
|
||||
protected function getSqlQuery(int $type): string
|
||||
{
|
||||
switch ($type) {
|
||||
case SqlArray::SQL_GET:
|
||||
return "SELECT value FROM \"{$this->table}\" WHERE key = :index";
|
||||
case SqlArray::SQL_SET:
|
||||
return "
|
||||
INSERT INTO \"{$this->table}\"
|
||||
(key,value)
|
||||
VALUES (:index, :value)
|
||||
ON CONFLICT (key) DO UPDATE SET value = :value
|
||||
";
|
||||
case SqlArray::SQL_UNSET:
|
||||
return "
|
||||
DELETE FROM \"{$this->table}\"
|
||||
WHERE key = :index
|
||||
";
|
||||
case SqlArray::SQL_COUNT:
|
||||
return "
|
||||
SELECT count(key) as count FROM \"{$this->table}\"
|
||||
";
|
||||
case SqlArray::SQL_ITERATE:
|
||||
return "
|
||||
SELECT key, value FROM \"{$this->table}\"
|
||||
";
|
||||
case SqlArray::SQL_CLEAR:
|
||||
return "
|
||||
DELETE FROM \"{$this->table}\"
|
||||
";
|
||||
}
|
||||
throw new Exception("An invalid statement type $type was provided!");
|
||||
}
|
||||
|
||||
protected function setSerializer(SerializerType $serializer): void
|
||||
{
|
||||
$this->serializer = match ($serializer) {
|
||||
|
@ -94,7 +94,7 @@ abstract class SqlArray extends DriverArray
|
||||
|
||||
$this->setCache($key, $value);
|
||||
|
||||
$result = $this->execute(
|
||||
$this->execute(
|
||||
$this->queries[self::SQL_SET],
|
||||
[
|
||||
'index' => $key,
|
||||
|
Loading…
x
Reference in New Issue
Block a user