From 29ce47251a14692a96b9f009d27a8ec465b94bc9 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sat, 12 May 2018 05:40:15 +0900 Subject: [PATCH] =?UTF-8?q?KVStorage=EA=B0=80=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=A0=20db=EB=A5=BC=20=EC=A7=81=EC=A0=91=20=EC=84=A0?= =?UTF-8?q?=ED=83=9D=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD.=20KVStorage=EB=A5=BC=20=EC=A0=84=EC=97=AD?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {hwe => src}/sammo/KVStorage.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) rename {hwe => src}/sammo/KVStorage.php (92%) diff --git a/hwe/sammo/KVStorage.php b/src/sammo/KVStorage.php similarity index 92% rename from hwe/sammo/KVStorage.php rename to src/sammo/KVStorage.php index 8902916b..e68fddea 100644 --- a/hwe/sammo/KVStorage.php +++ b/src/sammo/KVStorage.php @@ -2,10 +2,12 @@ namespace sammo; class KVStorage{ + private $db = null; private $storNamespace; private $cacheData = null; - public function __construct(string $storNamespace, bool $cacheMode=false){ + public function __construct(\MeekroDB $db, string $storNamespace, bool $cacheMode=false){ + $this->db = $db; $this->storNamespace = $storNamespace; if($cacheMode){ $this->cacheData = []; @@ -157,9 +159,8 @@ class KVStorage{ } private function getDBAll(): array{ - $db = DB::db(); $result = []; - foreach($db->queryAllLists( + foreach($this->db->queryAllLists( 'SELECT `key`, `value` FROM storage WHERE `namespace`=%s', $this->storNamespace ) as list($key, $value)) @@ -170,9 +171,8 @@ class KVStorage{ } private function getDBValues(array $keys): array{ - $db = DB::db(); $result = []; - foreach($db->queryAllLists( + foreach($this->db->queryAllLists( 'SELECT `key`, `value` FROM storage WHERE `namespace`=%s AND `key` IN %ls', $this->storNamespace, $keys @@ -189,8 +189,7 @@ class KVStorage{ } private function getDBValue($key){ - $db = DB::db(); - $value = $db->queryFirstField( + $value = $this->db->queryFirstField( 'SELECT `value` FROM storage WHERE `namespace`=%s AND `key`=%s', $this->storNamespace, $key @@ -205,8 +204,7 @@ class KVStorage{ if($value === null){ return $this->deleteDBValue($key); } - $db = DB::db(); - $db->insertUpdate('storage', [ + $this->db->insertUpdate('storage', [ 'namespace'=>$this->storNamespace, 'key'=>$key, 'value'=>Json::encode($value) @@ -215,8 +213,7 @@ class KVStorage{ } private function deleteDBValue($key):self{ - $db = DB::db(); - $db->delete('storage', [ + $this->db->delete('storage', [ 'namespace'=>$this->storNamespace, 'key'=>$key ]); @@ -224,8 +221,7 @@ class KVStorage{ } private function resetDBNamespace():self{ - $db = DB::db(); - $db->delete('storage', [ + $this->db->delete('storage', [ 'namespace'=>$this->storNamespace ]); return $this;