Skip to content

Commit

Permalink
Added Prisma.
Browse files Browse the repository at this point in the history
  • Loading branch information
sakibcy committed Apr 17, 2024
1 parent 173f1f2 commit 287f49e
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 1 deletion.
21 changes: 21 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -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}`);
Expand Down
80 changes: 80 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
Expand Down
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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, () => {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
20 changes: 20 additions & 0 deletions src/startup/db.ts
Original file line number Diff line number Diff line change
@@ -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: '[email protected]'}})
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)
// })

0 comments on commit 287f49e

Please sign in to comment.