From 64d6bdca1f9f83574557fa019af9894ed7a59eb7 Mon Sep 17 00:00:00 2001 From: flashwave Date: Fri, 21 Jul 2023 20:11:02 +0000 Subject: [PATCH] Added some of the database utilities from Misuzu to Index. --- VERSION | 2 +- src/Data/DbStatementCache.php | 44 +++++++++++++++++++++++++++++++++++ src/Data/DbTools.php | 17 +++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/Data/DbStatementCache.php diff --git a/VERSION b/VERSION index bee887d..37f3671 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2307.211801 +0.2307.212010 diff --git a/src/Data/DbStatementCache.php b/src/Data/DbStatementCache.php new file mode 100644 index 0000000..edb82d3 --- /dev/null +++ b/src/Data/DbStatementCache.php @@ -0,0 +1,44 @@ +dbConn = $dbConn; + } + + private static function hash(string $query): string { + return hash('xxh3', $query, true); + } + + public function get(string $query): IDbStatement { + $hash = self::hash($query); + + if(array_key_exists($hash, $this->stmts)) { + $stmt = $this->stmts[$hash]; + $stmt->reset(); + return $stmt; + } + + return $this->stmts[$hash] = $this->dbConn->prepare($query); + } + + public function remove(string $query): void { + unset($this->stmts[self::hash($query)]); + } + + public function clear(): void { + foreach($this->stmts as $stmt) + $stmt->close(); + $this->stmts = []; + } +} diff --git a/src/Data/DbTools.php b/src/Data/DbTools.php index 82996ae..a1063d3 100644 --- a/src/Data/DbTools.php +++ b/src/Data/DbTools.php @@ -1,10 +1,11 @@