Functionality that reads a csv file and adds it to the databas, using node js and prisma
The project is still in development and the next updates will focus on the following tasks:
- Check if it already exists in the database
- Method to get the entire listing
Before starting, make sure you've met the following requirements:
- You have installed the latest version of
Node JS
To install csv-file-reading, follow these steps:
Install dependencies :
yarn install
First remove the .exmple from the .env.exmple file, then add values for the following environment variables, PORT, DATABASE_URL
Running server:
yarn dev
Create table:
npx prisma migrate dev
To use csv-file-reading, follow these steps:
To use send a post to the route http://localhost:PORT UTILIZED/insertBooks, passing a multipart, named file and a csv file.
obs: the code was structured based on the use example worksheet, for the test to be successful, use the example worksheet, otherwise it will be necessary to adjust the code PORTA UTILIZED
Modifications for use:
- First I created your new migration structure, in the csv-file-reading/prisma/schema.prisma file run the command below. Creating the Migrate Prism:
yarn prisma
- Set your type in the csv-file-reading/src/types/list.ts
obs:From now on all changes will be made in the same file
- In the csv-file-reading/src/routes.ts file, replace the line 31ate to 35, with the structure of your type
- If your table didn't have a header that you want to remove, remove line 39, if necessary, skip the header, change const listWithoutHeader = list.slice(N, -1), where N will be the number of lines it will skip
- On line 42 change the destructuring as if type
- In line 43, if line 39 has been removed, change the listWithoutHeader to list variable and in the line below return the new list values to date
After making these changes, run the server, and process with a usage model
To contribute csv-file-reading, follow these steps:
- Fork this repository.
- Create a branch:
git checkout -b <branch_name>
. - Make your changes and commit them:
git commit -m '<message_commit>'
- Push to original branch:!git remote add origin https://:@github.com//reponame.git
- Create the pull request.
!git remote add origin https://:@github.com//https://github.com/ReisSouza/csv-file-reading.git
to create your personal access token -
in your GitHub account go to settings go to developer settings go to Personal Access Tokens generate new token make sure you save it as you only see it once
Alternatively, see the GitHub documentation at how to create a pull request.
MIT