Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostGreSQL integration: prisma ORM installed and POC written #8

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# prisma
.env
111 changes: 51 additions & 60 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 @@
"@nivo/core": "^0.80.0",
"@nivo/radar": "^0.80.0",
"@nivo/voronoi": "^0.80.0",
"@prisma/client": "^4.12.0-integration-rtld-deepbind.3",
"@rudderstack/rudder-sdk-node": "^2.0.2",
"@types/node": "18.11.14",
"@types/react": "18.0.26",
Expand Down Expand Up @@ -43,6 +44,7 @@
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"postcss": "^8.4.20",
"prisma": "^4.12.0-integration-rtld-deepbind.3",
"tailwindcss": "^3.2.4"
},
"browser": {
Expand Down
34 changes: 33 additions & 1 deletion pages/u.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getAuthUserId, getAuthUserName } from "../utils/auth";
import RepoList, { getRepoList } from "../views/RepoList";
import conn from "../utils/db";
import Footer from "../components/Footer";
import { PrismaClient } from '@prisma/client'

type ProfileProps = {
sessionObj: Session,
Expand Down Expand Up @@ -59,6 +60,37 @@ type BitbucketEmailObj = {
}

export const getServerSideProps: GetServerSideProps<ProfileProps> = async ({ req, res }) => {
// const my_repo = "mentorship-website";
const prisma = new PrismaClient();
async function main() {
// Prisma queries here
const allUsers = await prisma.users.findMany()
console.log(allUsers);
}

main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error("Prisma query failed", e);
await prisma.$disconnect();
process.exit(1);
})
// const result: object | null = await prisma.temp_devraw.groupBy({
// by: ['author_email'],
// _count: {
// commit_id: true,
// },
// where: {
// commit_json: {
// path: ['repo_name'],
// equals: my_repo,
// }
// }
// });
// console.log(result);

// check if user is logged in
const session = await getServerSession(req, res, authOptions);
if (!session) {
Expand Down Expand Up @@ -126,4 +158,4 @@ export const getServerSideProps: GetServerSideProps<ProfileProps> = async ({ req
}
}

export default Profile;
export default Profile;
71 changes: 71 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model commits {
commit_id String
author_email String
commit_json Json? @db.Json

@@id([commit_id, author_email])
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model devraw {
commit_id String?
author_email String?
commit_json Json? @db.Json
ts_raw BigInt?
ts DateTime? @db.Timestamp(6)
langs String[]

@@ignore
}

model repos {
id Int @id @default(autoincrement())
repo_name String?
auth_info Json? @db.Json
aliases String[]
org String?
git_url String[]
metadata Json? @db.Json
created_at DateTime? @default(now()) @db.Timestamptz(6)
repo_provider String?
repo_owner String?

@@unique([repo_name, repo_owner, repo_provider], map: "uniquerepo")
}

model temp_devraw {
commit_id String
author_email String
commit_json Json? @db.Json

@@id([commit_id, author_email])
}

model tokens {
id Int @id @default(autoincrement())
auth_info Json? @db.Json
created_at DateTime? @default(now()) @db.Timestamptz(6)
repo String[]
}

model users {
id Int @id @default(autoincrement())
name String?
profile_url String?
role String?
auth_info Json? @db.Json
aliases String[]
org String?
code_url String[]
social_url String[]
repos Int[]
}