title: How to push TSV data from POST request into a Postgres (Prisma ORM) database
body: <p><strong>My Goal</strong></p>
  <p>I am working on a NextJS &amp; Prisma ORM (Postgres) application and (due to being very new to any backend development work) am struggling with understanding how to structure my application and where to make certain function calls.</p>
  <p>The aim of my application is to take a user submitted externally hosted TSV (tab separated values) file and push it into a new Postgres database.</p>
  <p><strong>Current Status</strong></p>
  <p>So far I have developed a form on the front end of the application (irrelevant validation / styling code has been removed from this excerpt):</p>
  <pre><code>const Feeds = ({ visible }) =&gt; {
  
      const handleSubmit = async (e) =&gt; {
  
          e.preventDefault();
  
          try {
              const body = { feedTitle, websiteUrl, currency, feedUrl };
              await fetch('/api/form', {
                  method: 'POST',
                  headers: { 'Content-Type': 'application/json' },
                  body: JSON.stringify(body)
              });
              console.log('body: ', body);
          } catch (error) {
              console.error(error);
          }
      };
  
  
      return (
          &lt;Form onSubmit={(e) =&gt; handleSubmit(e)} id=&quot;myForm&quot; visible={visible}&gt;
              &lt;HeaderContainer&gt;
                  &lt;Header&gt;Add a new feed&lt;/Header&gt;
                  &lt;HeaderDescription&gt;Please complete all of the required fields below and submit to add a new feed.&lt;/HeaderDescription&gt;
              &lt;/HeaderContainer&gt;
              &lt;FormContainer&gt;
                  &lt;InputContainer&gt;
                      &lt;Label&gt;Feed title&lt;/Label&gt;
                      &lt;Input type=&quot;text&quot; placeholder=&quot;&quot; value={feedTitle} onChange={(e) =&gt; handleChangeFeedTitle(e)} /&gt;
                  &lt;/InputContainer&gt;
                  &lt;InputContainer&gt;
                      &lt;Label&gt;Website url&lt;/Label&gt;
                      &lt;Input type=&quot;text&quot; placeholder=&quot;&quot; value={websiteUrl} onChange={(e) =&gt; handleChangeWebsiteUrl(e)} /&gt;
                  &lt;/InputContainer&gt;
                  &lt;InputContainer&gt;
                      &lt;Label&gt;Currency&lt;/Label&gt;
                      &lt;Select onChange={(e) =&gt; handleChangeCurrency(e)} name=&quot;currency&quot; id=&quot;currency-select&quot;&gt;
                          {currencies.map((option, index) =&gt; (
                              &lt;option key={index} value={option.value}&gt;
                                  {option.text}
                              &lt;/option&gt;
                          ))}
                      &lt;/Select&gt;
                  &lt;/InputContainer&gt;
                  &lt;InputContainer&gt;
                      &lt;Label&gt;Feed url&lt;/Label&gt;
                      &lt;Input type=&quot;text&quot; placeholder=&quot;&quot; value={feedUrl} onChange={(e) =&gt; handleChangeFeedUrl(e)} /&gt;
                  &lt;/InputContainer&gt;
              &lt;/FormContainer&gt;
              {allValid ? &lt;Button type=&quot;submit&quot; form=&quot;myForm&quot;&gt;Save&lt;/Button&gt; : &lt;DisabledButton&gt;Save&lt;/DisabledButton&gt;}
          &lt;/Form&gt;
      )
  };
  
  export default Feeds;
  </code></pre>
  <p>On submission, this POST request hits the forms API endpoint:</p>
  <pre><code>const handler = async (req, res) =&gt; {
      
      const body = req.body;
  
      const response = await fetch(body.feedUrl) 
          .then(res =&gt; res.text())
          .then(content =&gt; console.log(content))
          .catch(err =&gt; console.error(err));
  
      console.log('body: ', body);
  
      res.status(200).json({ data: `${body}` })
  };
  
  export default handler;
  </code></pre>
  <p>At this point I can see that the TSV file is being logged to my terminal &amp; console.</p>
  <p>The next step will be to format the TSV so that it is ready to be pushed into the database. I'm confident I can achieve that once I know what format it needs to be in. But beyond this I am a bit lost.</p>
  <p><strong>The Problem</strong></p>
  <p>Ultimately, I know that I need to push this data into my Postgres (Prisma ORM) database, but I'm not sure if this should be done as part of the above handler function... Or should there be another step where the TSV is saved elsewhere first (some sort of storage? GCP?) and then  subsequently sent to the database?</p>
  <p>The TSV files could be quite large (up to 5mb), and so I assume putting any TSV tidying logic + sending off to the database in a POST request / response is not a great idea.</p>
  <p>If anybody is able to outline the best architecture to go forward from this point, that would be greatly appreciated.</p>
  <p>Thank you!!!</p>