/** * @param AbstractModel $object */ public function save(AbstractModel $object) { $record = $this->entityMapper->objectToRecord($object); if ($record['id']) { $where = ['id' => (int) $record['id']]; $this->db->update($this->tablename, $record, $where); } else { $insertId = $this->db->insert($this->tablename, $record); $object->setId($insertId); } }
/** * @test */ public function delete() { $this->fixture->insert('item', ['title' => '1']); $this->fixture->insert('item', ['title' => '2']); $todelete = $this->fixture->insert('item', ['title' => '3']); $count = $this->fixture->count('item'); $this->fixture->delete('item', ['id' => $todelete]); $this->assertSame($count - 1, $this->fixture->count('item')); $this->fixture->delete('item'); $this->assertSame(0, $this->fixture->count('item')); }
/** * @param int $version */ protected function setCurrentMigrationVersion($version) { if (count($this->db->query("SHOW TABLES LIKE 'migration_ver'")) < 1) { $sql = "CREATE TABLE IF NOT EXISTS `migration_ver` (`version` int(11) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"; $this->db->execute($sql); } $data = ['version' => $version]; if ($this->db->count('migration_ver') < 1) { $this->db->insert('migration_ver', $data); } else { $this->db->update('migration_ver', $data, ['version!' => '0']); } }