function loadTeaLocations() {
  client.query('SELECT COUNT(*) FROM tea_locations')
    .then(results => {
      if (!parseInt(results.rows[0].count)) {
        fs.readFile('./public/data/data.json', (err, fd) => {
          if (err) return console.error(err);
          JSON.parse(fd.toString()).forEach(ele => {
            client.query(`
            INSERT INTO
            tea_locations(shopname, "shopUrl", description, street, city, state, zip, country, category)
            VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);`,
            [ele.shopname, ele.shopUrl, ele.description, ele.street, ele.city, ele.state, ele.zip, ele.country, ele.category]
            )
          })
        })
      }
    })
}
//These functions initilize our database and populate it from the JSON file "data". We do need 'fs' for this.
These functions initilize our database and populate it from the JSON file "data". We do need 'fs' for this.
These functions initilize our database and populate it from the JSON file " data " . We do need ' fs ' for this .
function loadTeaLocations() {
  client.query('SELECT COUNT(*) FROM tea_locations')
    .then(results => {
      if (!parseInt(results.rows[0].count)) {
        fs.readFile('./public/data/data.json', (err, fd) => {
          if (err) return console.error(err);
          JSON.parse(fd.toString()).forEach(ele => {
            client.query(`
            INSERT INTO
            tea_locations(shopname, "shopUrl", description, street, city, state, zip, country, category)
            VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);`,
            [ele.shopname, ele.shopUrl, ele.description, ele.street, ele.city, ele.state, ele.zip, ele.country, ele.category]
            )
          })
        })
      }
    })
}
function loadTeaLocations ( ) { client . query ( 'SELECT COUNT(*) FROM tea_locations' ) . then ( results => { if ( ! parseInt ( results . rows [ 0 ] . count ) ) { fs . readFile ( './public/data/data.json' , ( err , fd ) => { if ( err ) return console . error ( err ) ; JSON . parse ( fd . toString ( ) ) . forEach ( ele => { client . query ( ` ` , [ ele . shopname , ele . shopUrl , ele . description , ele . street , ele . city , ele . state , ele . zip , ele . country , ele . category ] ) } ) } ) } } ) }
These functions initilize our database and populate it from the JSON file "data".
These functions initilize our database and populate it from the JSON file " data " .