1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 18:51:13 +01:00

Update example

This commit is contained in:
Daniil Gentili 2023-05-02 18:48:02 +02:00
parent 26b900cf61
commit 6f5dec19ec
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
4 changed files with 4 additions and 18 deletions

View File

@ -24,6 +24,7 @@ use danog\MadelineProto\Settings;
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; use danog\MadelineProto\Settings\Database\Redis;
use danog\MadelineProto\Settings\Database\SerializerType;
// If a stable version of MadelineProto was installed via composer, load composer autoloader // If a stable version of MadelineProto was installed via composer, load composer autoloader
if (file_exists('vendor/autoload.php')) { if (file_exists('vendor/autoload.php')) {
@ -57,7 +58,7 @@ class MyEventHandler extends EventHandler
* @see https://docs.madelineproto.xyz/docs/DATABASE.html * @see https://docs.madelineproto.xyz/docs/DATABASE.html
*/ */
protected static array $dbProperties = [ protected static array $dbProperties = [
'dataStoredOnDb' => [], 'dataStoredOnDb' => ['serializer' => SerializerType::SERIALIZE],
]; ];
/** /**

View File

@ -14,7 +14,7 @@ use danog\MadelineProto\Settings\DatabaseAbstract;
use InvalidArgumentException; use InvalidArgumentException;
/** /**
* @psalm-type TOrmConfig=array{serializer?: SerializerType, enableCache?: bool, cacheTtl?: int} * @psalm-import-type TOrmConfig from DbPropertiesTrait
* This factory class initializes the correct database backend for MadelineProto. * This factory class initializes the correct database backend for MadelineProto.
*/ */
abstract class DbPropertiesFactory abstract class DbPropertiesFactory

View File

@ -15,8 +15,7 @@ use function Amp\Future\await;
* *
* You will have to define a `$dbProperties` static array property, with a list of properties you want to store to a database. * You will have to define a `$dbProperties` static array property, with a list of properties you want to store to a database.
* *
* @psalm-import-type TOrmConfig from DbPropertiesFactory * @psalm-type TOrmConfig=array{serializer?: SerializerType, enableCache?: bool, cacheTtl?: int}
*
* @property array<string, TOrmConfig> $dbProperties * @property array<string, TOrmConfig> $dbProperties
*/ */
trait DbPropertiesTrait trait DbPropertiesTrait

View File

@ -53,20 +53,6 @@ final class Postgres
ENCODING utf8 ENCODING utf8
"); ");
} }
$connection->query("
CREATE OR REPLACE FUNCTION update_ts()
RETURNS TRIGGER AS $$
BEGIN
IF row(NEW.*) IS DISTINCT FROM row(OLD.*) THEN
NEW.ts = now();
RETURN NEW;
ELSE
RETURN OLD;
END IF;
END;
$$ language 'plpgsql'
");
$connection->close(); $connection->close();
} catch (Throwable $e) { } catch (Throwable $e) {
Logger::log($e->getMessage(), Logger::ERROR); Logger::log($e->getMessage(), Logger::ERROR);