Psalm improvements

This commit is contained in:
Daniil Gentili 2020-10-23 18:19:20 +02:00
parent f7ecafb086
commit 47b808ca9b
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 26 additions and 14 deletions

View File

@ -23,9 +23,9 @@ use danog\MadelineProto\API;
use danog\MadelineProto\EventHandler; use danog\MadelineProto\EventHandler;
use danog\MadelineProto\Logger; use danog\MadelineProto\Logger;
use danog\MadelineProto\Settings; use danog\MadelineProto\Settings;
use danog\MadelineProto\Settings\Database\Redis;
use danog\MadelineProto\Settings\Database\Mysql; use danog\MadelineProto\Settings\Database\Mysql;
use danog\MadelineProto\Settings\Database\Postgres; use danog\MadelineProto\Settings\Database\Postgres;
use danog\MadelineProto\Settings\Database\Redis;
/* /*
* Various ways to load MadelineProto * Various ways to load MadelineProto

View File

@ -24,24 +24,24 @@ class MemoryArray extends \ArrayIterator implements DbArray
* Get instance. * Get instance.
* *
* @param string $table * @param string $table
* @param mixed $value * @param mixed $previous
* @param Memory $settings * @param Memory $settings
* @return Promise<self> * @return Promise<self>
*/ */
public static function getInstance(string $table, $value, $settings): Promise public static function getInstance(string $table, $previous, $settings): Promise
{ {
return call(static function () use ($value) { return call(static function () use ($previous) {
if ($value instanceof MemoryArray) { if ($previous instanceof MemoryArray) {
return $value; return $previous;
} }
if ($value instanceof DbArray) { if ($previous instanceof DbArray) {
Logger::log("Loading database to memory. Please wait.", Logger::WARNING); Logger::log("Loading database to memory. Please wait.", Logger::WARNING);
if ($value instanceof DriverArray) { if ($previous instanceof DriverArray) {
yield from $value->initStartup(); yield from $previous->initStartup();
} }
$value = yield $value->getArrayCopy(); $previous = yield $previous->getArrayCopy();
} }
return new static($value); return new static($previous);
}); });
} }

View File

@ -58,6 +58,12 @@ class MysqlArray extends SqlArray
} }
/**
* Get value from row.
*
* @param array $row
* @return null|mixed
*/
protected function getValue(array $row) protected function getValue(array $row)
{ {
if ($row) { if ($row) {

View File

@ -72,6 +72,12 @@ class PostgresArray extends SqlArray
} }
} }
/**
* Get value from row.
*
* @param array $row
* @return null|mixed
*/
protected function getValue(array $row) protected function getValue(array $row)
{ {
if ($row) { if ($row) {
@ -82,7 +88,7 @@ class PostgresArray extends SqlArray
return $row['value']; return $row['value'];
} }
if ($row['value'][0] === '\\') { if ($row['value'][0] === '\\') {
$row['value'] = hex2bin(substr($row['value'], 2)); $row['value'] = \hex2bin(\substr($row['value'], 2));
} }
return \unserialize($row['value']); return \unserialize($row['value']);
} }
@ -158,7 +164,7 @@ class PostgresArray extends SqlArray
protected function renameTable(string $from, string $to): \Generator protected function renameTable(string $from, string $to): \Generator
{ {
Logger::log("Renaming table {$from} to {$to}", Logger::WARNING); Logger::log("Renaming table {$from} to {$to}", Logger::WARNING);
yield $this->db->query(" yield $this->db->query("
DROP TABLE IF EXISTS \"{$to}\"; DROP TABLE IF EXISTS \"{$to}\";
"); ");

View File

@ -34,7 +34,7 @@ abstract class SqlArray extends DriverArray
* Get value from row. * Get value from row.
* *
* @param array $row * @param array $row
* @return void * @return null|mixed
*/ */
abstract protected function getValue(array $row); abstract protected function getValue(array $row);