/** * test get() with a criteria * * requires get() to be implemented */ public function testGet() { $limit = 10; $db = $this->getDb(); $table = $this->getTable(__FUNCTION__); $_id_list = $this->insert($table, $limit); $where_criteria = new MingoCriteria(); $where_criteria->in_id($_id_list); $where_criteria->setLimit($limit); $_id_seen_list = array(); for ($offset = 0, $max = count($_id_list); $offset < $max; $offset += $limit) { $where_criteria->setOffset($offset); $list = $db->get($table, $where_criteria); $this->assertInternalType('array', $list); $this->assertEquals($limit, count($list)); foreach ($list as $map) { $this->assertArrayHasKey('_id', $map); // make sure this was an id we wanted... $_id = (string) $map['_id']; $this->assertContains($_id, $_id_list); // make sure we aren't getting any dupes... $this->assertNotContains($_id, $_id_seen_list); $_id_seen_list[] = $_id; } //foreach } //for // make sure counts and results are right when we have mutltiple ids that are the same... $where_criteria = new MingoCriteria(); $where_criteria->in_id(array($_id_list[0], $_id_list[1], $_id_list[0])); $list = $db->get($table, $where_criteria); $this->assertEquals(2, count($list)); }
/** * get the first found row in $table according to $where_criteria * * @param MingoTable $table * @param MingoCriteria $where_criteria * @return array */ public function getOne(MingoTable $table, MingoCriteria $where_criteria = null) { // set up to only select 1... if ($where_criteria === null) { $where_criteria = new MingoCriteria(); } //if $where_criteria->setLimit(1); $where_criteria->setPage(0); $where_criteria->setOffset(0); $ret_list = $this->get($table, $where_criteria); $ret_map = reset($ret_list); if ($ret_map === false) { $ret_map = array(); } //if return $ret_map; }
/** * goes through the master $table and adds the contents to the index table * * @param \MingoTable $table the main table, not the index table * @param \MingoIndex $index the index that will be used to populate the tables */ protected function populateIndex($table, MingoIndex $index) { $ret_bool = false; $where_criteria = new MingoCriteria(); $limit = 500; $offset = 0; $where_criteria->setLimit($limit); $where_criteria->setOffset($offset); // get results from the table and add them to the index... while ($map_list = $this->get($table, $where_criteria)) { foreach ($map_list as $map) { $ret_bool = $this->insertIndex($table, $map['_id'], $map, $index); } //foreach $offset += $limit; $where_criteria->setOffset($offset); } //while return $ret_bool; }