|
<?php |
|
|
|
namespace PicoDb; |
|
|
|
use PDO; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Hashtable extends Table |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
private $keyColumn = 'key'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private $valueColumn = 'value'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function columnKey($column) |
|
{ |
|
$this->keyColumn = $column; |
|
return $this; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function columnValue($column) |
|
{ |
|
$this->valueColumn = $column; |
|
return $this; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function put(array $hashmap) |
|
{ |
|
return $this->db->getDriver()->upsert($this->getName(), $this->keyColumn, $this->valueColumn, $hashmap); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function get() |
|
{ |
|
$hashmap = array(); |
|
|
|
|
|
if (func_num_args() > 0) { |
|
$this->in($this->keyColumn, func_get_args()); |
|
} |
|
|
|
|
|
$this->columns($this->keyColumn, $this->valueColumn); |
|
|
|
$rq = $this->db->execute($this->buildSelectQuery(), $this->conditionBuilder->getValues()); |
|
$rows = $rq->fetchAll(PDO::FETCH_NUM); |
|
|
|
foreach ($rows as $row) { |
|
$hashmap[$row[0]] = $row[1]; |
|
} |
|
|
|
return $hashmap; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getAll($key, $value) |
|
{ |
|
$this->keyColumn = $key; |
|
$this->valueColumn = $value; |
|
return $this->get(); |
|
} |
|
} |
|
|