1
0
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:
Daniil Gentili 2023-05-26 16:59:32 +02:00
parent 94706cb0a8
commit de7676fc98
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 40 additions and 2 deletions

View File

@ -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';

View File

@ -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) {

View File

@ -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,