diff --git a/.gitignore b/.gitignore index 22f5e96..4e72415 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ dist/ .env -.DS_Store \ No newline at end of file +.DS_Store +backend/data/ diff --git a/server/package-lock.json b/backend/package-lock.json similarity index 99% rename from server/package-lock.json rename to backend/package-lock.json index c6b99b7..4b04b54 100644 --- a/server/package-lock.json +++ b/backend/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "@apollo/server": "^5.5.1", + "csv-parse": "^7.0.3", "dotenv": "^18.0.5", "graphql": "^16.14.2", "pg": "^8.23.1" @@ -1358,6 +1359,12 @@ "node": ">=16.0.0" } }, + "node_modules/csv-parse": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-7.0.3.tgz", + "integrity": "sha512-YFd3QM/yo17vH91L1IOZuvl09zM0zEEtdfTcOCKWcMdM++MNaQSyp09slXyFCLaPXvHstQFx/xC8myiFHSMUvw==", + "license": "MIT" + }, "node_modules/debug": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", diff --git a/server/package.json b/backend/package.json similarity index 79% rename from server/package.json rename to backend/package.json index c31e676..20d2eff 100644 --- a/server/package.json +++ b/backend/package.json @@ -1,11 +1,12 @@ { - "name": "server", + "name": "backend", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "dev": "tsx watch src/index.ts", - "start": "tsx src/index.ts" + "start": "tsx src/index.ts", + "import": "tsx scripts/import.ts" }, "keywords": [], "author": "", @@ -13,6 +14,7 @@ "type": "module", "dependencies": { "@apollo/server": "^5.5.1", + "csv-parse": "^7.0.3", "dotenv": "^18.0.5", "graphql": "^16.14.2", "pg": "^8.23.1" diff --git a/backend/scripts/import.ts b/backend/scripts/import.ts new file mode 100644 index 0000000..9675f0d --- /dev/null +++ b/backend/scripts/import.ts @@ -0,0 +1,17 @@ +import { createReadStream } from "node:fs"; +import { parse } from "csv-parse"; + +const WINES_FILE = "data/XWines_Test_100_wines.csv"; + +async function main() { + const parser = createReadStream(WINES_FILE).pipe(parse({ columns: true })); + + let count = 0; + for await (const row of parser) { + if (count === 0) console.log(row); + count++; + } + console.log(`Leste ${count} rader`); +} + +main(); \ No newline at end of file diff --git a/server/src/db.ts b/backend/src/db.ts similarity index 100% rename from server/src/db.ts rename to backend/src/db.ts diff --git a/server/src/index.ts b/backend/src/index.ts similarity index 100% rename from server/src/index.ts rename to backend/src/index.ts diff --git a/server/tsconfig.json b/backend/tsconfig.json similarity index 100% rename from server/tsconfig.json rename to backend/tsconfig.json