diff --git a/dist/index.js b/dist/index.js index 924309f..423104b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,13 +1,34 @@ "use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const express_1 = __importDefault(require("express")); const dotenv_1 = __importDefault(require("dotenv")); +const client_1 = require("@prisma/client"); +const prisma = new client_1.PrismaClient(); +const db_1 = __importDefault(require("./startup/db")); dotenv_1.default.config(); const app = (0, express_1.default)(); require('./startup/routes')(app); +(0, db_1.default)() + .then(() => __awaiter(void 0, void 0, void 0, function* () { + yield prisma.$disconnect(); +})) + .catch((e) => __awaiter(void 0, void 0, void 0, function* () { + console.error(e); + yield prisma.$disconnect(); + process.exit(1); +})); const port = process.env.PORT || 3000; app.listen(port, () => { console.log(`[server]: Server is running at http://localhost:${port}`); diff --git a/package-lock.json b/package-lock.json index 9bbd6de..a93356b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@google-cloud/aiplatform": "^3.18.0", "@google-cloud/translate": "^8.1.0", "@google-cloud/vertexai": "^1.0.0", + "@prisma/client": "^5.12.1", "concurrently": "^8.2.2", "dotenv": "^16.4.5", "express": "^4.19.2" @@ -20,6 +21,7 @@ "@types/express": "^4.17.21", "@types/node": "^20.12.2", "nodemon": "^3.1.0", + "prisma": "^5.12.1", "ts-node": "^10.9.2", "typescript": "^5.4.3" } @@ -184,6 +186,68 @@ "url": "https://opencollective.com/js-sdsl" } }, + "node_modules/@prisma/client": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.12.1.tgz", + "integrity": "sha512-6/JnizEdlSBxDIdiLbrBdMW5NqDxOmhXAJaNXiPpgzAPr/nLZResT6MMpbOHLo5yAbQ1Vv5UU8PTPRzb0WIxdA==", + "hasInstallScript": true, + "engines": { + "node": ">=16.13" + }, + "peerDependencies": { + "prisma": "*" + }, + "peerDependenciesMeta": { + "prisma": { + "optional": true + } + } + }, + "node_modules/@prisma/debug": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.12.1.tgz", + "integrity": "sha512-kd/wNsR0klrv79o1ITsbWxYyh4QWuBidvxsXSParPsYSu0ircUmNk3q4ojsgNc3/81b0ozg76iastOG43tbf8A==", + "devOptional": true + }, + "node_modules/@prisma/engines": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.12.1.tgz", + "integrity": "sha512-HQDdglLw2bZR/TXD2Y+YfDMvi5Q8H+acbswqOsWyq9pPjBLYJ6gzM+ptlTU/AV6tl0XSZLU1/7F4qaWa8bqpJA==", + "devOptional": true, + "hasInstallScript": true, + "dependencies": { + "@prisma/debug": "5.12.1", + "@prisma/engines-version": "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab", + "@prisma/fetch-engine": "5.12.1", + "@prisma/get-platform": "5.12.1" + } + }, + "node_modules/@prisma/engines-version": { + "version": "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab.tgz", + "integrity": "sha512-6yvO8s80Tym61aB4QNtYZfWVmE3pwqe807jEtzm8C5VDe7nw8O1FGX3TXUaXmWV0fQTIAfRbeL2Gwrndabp/0g==", + "devOptional": true + }, + "node_modules/@prisma/fetch-engine": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.12.1.tgz", + "integrity": "sha512-qSs3KcX1HKcea1A+hlJVK/ljj0PNIUHDxAayGMvgJBqmaN32P9tCidlKz1EGv6WoRFICYnk3Dd/YFLBwnFIozA==", + "devOptional": true, + "dependencies": { + "@prisma/debug": "5.12.1", + "@prisma/engines-version": "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab", + "@prisma/get-platform": "5.12.1" + } + }, + "node_modules/@prisma/get-platform": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.12.1.tgz", + "integrity": "sha512-pgIR+pSvhYHiUcqXVEZS31NrFOTENC9yFUdEAcx7cdQBoZPmHVjtjN4Ss6NzVDMYPrKJJ51U14EhEoeuBlMioQ==", + "devOptional": true, + "dependencies": { + "@prisma/debug": "5.12.1" + } + }, "node_modules/@protobufjs/aspromise": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", @@ -1826,6 +1890,22 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/prisma": { + "version": "5.12.1", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.12.1.tgz", + "integrity": "sha512-SkMnb6wyIxTv9ACqiHBI2u9gD6y98qXRoCoLEnZsF6yee5Qg828G+ARrESN+lQHdw4maSZFFSBPPDpvSiVTo0Q==", + "devOptional": true, + "hasInstallScript": true, + "dependencies": { + "@prisma/engines": "5.12.1" + }, + "bin": { + "prisma": "build/index.js" + }, + "engines": { + "node": ">=16.13" + } + }, "node_modules/proto3-json-serializer": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/proto3-json-serializer/-/proto3-json-serializer-2.0.1.tgz", diff --git a/package.json b/package.json index 29e0dfd..0032b4d 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@google-cloud/aiplatform": "^3.18.0", "@google-cloud/translate": "^8.1.0", "@google-cloud/vertexai": "^1.0.0", + "@prisma/client": "^5.12.1", "concurrently": "^8.2.2", "dotenv": "^16.4.5", "express": "^4.19.2" @@ -24,6 +25,7 @@ "@types/express": "^4.17.21", "@types/node": "^20.12.2", "nodemon": "^3.1.0", + "prisma": "^5.12.1", "ts-node": "^10.9.2", "typescript": "^5.4.3" } diff --git a/src/index.ts b/src/index.ts index 3bb923e..fb5451c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,25 @@ import express, {Express, Request, Response} from "express"; import dotenv from "dotenv"; +import { PrismaClient } from '@prisma/client' +const prisma = new PrismaClient() + +import db from "./startup/db"; dotenv.config(); + const app: Express = express(); require('./startup/routes')(app); +db() + .then(async () => { + await prisma.$disconnect() + }) + .catch(async (e) => { + console.error(e) + await prisma.$disconnect() + process.exit(1) + }) + const port = process.env.PORT || 3000; app.listen(port, () => { diff --git a/src/routes/entry.ts b/src/routes/entry.ts index 21a62cc..5a7fe3c 100644 --- a/src/routes/entry.ts +++ b/src/routes/entry.ts @@ -3,7 +3,7 @@ import express, {Request, Response} from "express"; const router = express.Router(); router.get("/", (req: Request, res: Response) => { - res.send("Testing 8:10pm") + res.send("Testing 8:10pm"); }); export default router; \ No newline at end of file diff --git a/src/startup/db.ts b/src/startup/db.ts new file mode 100644 index 0000000..cb8245d --- /dev/null +++ b/src/startup/db.ts @@ -0,0 +1,20 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +export default async function db() { + const user = await prisma.user.create({ data: { name: 'DEMO', email: 'demo4@prisma.com'}}) + console.log(user) + console.log(user) + const allUsers = await prisma.user.findMany() + console.log(allUsers)} + +// db() +// .then(async () => { +// await prisma.$disconnect() +// }) +// .catch(async (e) => { +// console.error(e) +// await prisma.$disconnect() +// process.exit(1) +// }) \ No newline at end of file