title: How to not insert two of the same values
body: <p>I'm using an input to allow user's to select files from their computer and add it to a list. I'm doing this by using a promise to load the files and creating an array of promises and adding that to my state</p>
  
  <p><strong>React JS</strong></p>
  
  <pre><code>this.state = {
    files: [],
  };
  
  const readFile = (file) =&gt; {
  
      const fileReader = new FileReader();
  
      return new Promise((resolve, reject) =&gt; {
  
        fileReader.onerror = (error) =&gt; {
          reject({ error })
        }
  
         fileReader.onload = (e) =&gt; {
          resolve({
            name: file.name.replace( /_|\.mp3/gi, " "),
            link: e.target.result,
            id: id++,
  
          })
        }
  
        fileReader.readAsDataURL(file);
  
      })
    }
    const allReaders = Array.from(event.target.files).map(readFile)
  
    Promise.all(allReaders)
      .then(fileList =&gt; {
        console.log(this.state.files)
        this.setState({ files: fileList });
      })
      .catch(error =&gt; {
         console.error(error)
      });
  
  
  }
  </code></pre>
  
  <p>I'm then mapping through my files array to add those files to a list of text inputs. They're also able to reorder the list as well as change the text for each list item. </p>
  
  <p>After that they will be able to save the list information to a database using a button. </p>
  
  <p><strong>React JS</strong></p>
  
  <pre><code>save(event) {
     event.preventDefault();
     let files = this.state.files;
  
  let data = files.map(( { name }  , index) =&gt; ({ name, index : index }));
  
  
   let request = new Request('http://localhost:3000/songs', {
      method: 'POST',
      headers: new Headers({ 'Content-Type': 'application/json' }),
      body: JSON.stringify(data)
    });
  
         fetch(request)
        .then((response) =&gt;
          response.json())
            .then((data) =&gt; {
            })
            .catch((error) =&gt; {
              console.log(error)
            })
  
  }
  </code></pre>
  
  <p><strong>Node JS</strong></p>
  
  <pre><code>*queries.js*
  const addSong = (request, response) =&gt; {
    const id = parseInt(request.params.id)
    const { name, link, index } = request.body;
  
  for (var i = 0; i &lt; request.body.length; i++) {
    pool.query('INSERT INTO songs (name, link, index) VALUES ($1, $2, $3) RETURNING *', [request.body[i].name, request.body[i].link, request.body[i].index], (error, results) =&gt; {
    if (error) {
      throw error
      console.log(error)
    } else {
      console.log("Rows " + JSON.stringify(results.rows));
  
    }
   });
  }
  }
  
  *index.js*
  const app = express();
  const db = require('./queries');
  app.post('/songs', db.addSong)
  </code></pre>
  
  <p>It works but if I click save twice it saves the same data to the database. I guess what I want to be able to do is not save the object if it contains the same index as another object. </p>