Fixed DB class not finding $manager + Refactor methods to be similar to Node

This commit is contained in:
Niko 2022-02-10 02:07:53 +01:00
parent 3a3cf576e5
commit f9540b9aab
1 changed files with 11 additions and 2 deletions

View File

@ -13,9 +13,18 @@ class DB {
$this->db_name = $db_name; $this->db_name = $db_name;
} }
function query($table, $q) { function findOne($table, $q) {
$result = $this->find($table, $q);
if ($result === null)
return null;
if (count($result) === 0)
return null;
return $result[0];
}
function find($table, $q) {
$query = new MongoDB\Driver\Query($q); $query = new MongoDB\Driver\Query($q);
$cursor = $manager->executeQuery($this->db_name.'.'.$table, $query); $cursor = $this->manager->executeQuery($this->db_name.'.'.$table, $query);
return $cursor->toArray(); return $cursor->toArray();
} }
} }