From ccb7f8886a91e904d0c949bf18b6953ab6f860cb Mon Sep 17 00:00:00 2001 From: Trehinos Date: Tue, 31 Jan 2023 00:59:45 +0100 Subject: [PATCH] Database : JsonType --- thor/Database/PdoExtension/PdoRequester.php | 2 +- thor/Database/PdoTable/TableType/JsonType.php | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 thor/Database/PdoTable/TableType/JsonType.php diff --git a/thor/Database/PdoExtension/PdoRequester.php b/thor/Database/PdoExtension/PdoRequester.php index 8530995..fa1fd57 100644 --- a/thor/Database/PdoExtension/PdoRequester.php +++ b/thor/Database/PdoExtension/PdoRequester.php @@ -104,7 +104,7 @@ final public function getPdoHandler(): PdoHandler return $this->handler; } - static function in(array $elements) : string + public static function in(array $elements) : string { return '(' . implode(',', array_fill(0, count($elements), '?')) . ')'; } diff --git a/thor/Database/PdoTable/TableType/JsonType.php b/thor/Database/PdoTable/TableType/JsonType.php new file mode 100644 index 0000000..cb74cfe --- /dev/null +++ b/thor/Database/PdoTable/TableType/JsonType.php @@ -0,0 +1,47 @@ +associative); + } + + /** + * @param mixed $phpValue + * + * @return string + */ + public function toSqlValue(mixed $phpValue): string + { + return json_encode($phpValue); + } +}