No more lightdb:delete v11

This commit is contained in:
xdrm-brackets 2017-09-14 16:20:18 +02:00
parent abe8ec2340
commit 766b5a7011
1 changed files with 4 additions and 7 deletions

View File

@ -122,19 +122,16 @@
* *
*/ */
public function insert($key, $data){ public function insert($key, $data){
$already_line = $this->line;
/* (1) On vérifie que la clé est unique */ /* (1) On vérifie que la clé est unique */
if( array_key_exists($key, $this->index) ) if( array_key_exists($key, $this->index) )
$already_line = $this->index[$key]['line']; return false;
$key = (string) $key; $key = (string) $key;
/* (2) On ajoute les données aux fichier */ /* (2) On ajoute les données aux fichier */
$json_data = json_encode($data); $json_data = json_encode($data);
$this->driver->seek($already_line); $this->driver->seek($this->line);
if( $already_line == $this->line ) $this->line++;
$this->line++;
$written = $this->driver->fwrite( $json_data.PHP_EOL ); $written = $this->driver->fwrite( $json_data.PHP_EOL );
// Si erreur d'écriture, on retourne FALSE // Si erreur d'écriture, on retourne FALSE
@ -143,7 +140,7 @@
/* (3) On enregistre l'index */ /* (3) On enregistre l'index */
$this->index[$key] = [ $this->index[$key] = [
'line' => $already_line - 1, 'line' => $this->line - 1,
'hash' => sha1($json_data) 'hash' => sha1($json_data)
]; ];