-
-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: initialises prisma orm * chore: specifies prisma schema path
- Loading branch information
Showing
16 changed files
with
376 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,5 +59,8 @@ | |
"patchedDependencies": { | ||
"@types/[email protected]": "patches/@[email protected]" | ||
} | ||
}, | ||
"prisma": { | ||
"schema": "packages/db/prisma/schema.prisma" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { greetingRouter } from './routers/greeting'; | ||
import { userRouter } from './routers/user'; | ||
import { createRouter } from './setup/trpc'; | ||
|
||
export const appRouter = createRouter({ | ||
greeting: greetingRouter, | ||
user: userRouter, | ||
}); | ||
|
||
export type AppRouter = typeof appRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createRouter, publicProcedure } from '../../setup/trpc'; | ||
|
||
export const userRouter = createRouter({ | ||
find: createRouter({ | ||
all: publicProcedure.query(async ({ ctx }) => { | ||
return await ctx.prisma.user.findMany(); | ||
}), | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { type User } from '@noodle/db'; | ||
|
||
import { userRouter } from '.'; | ||
import { prismaMock } from '../../../vitest.setup'; | ||
import { createInnerContext } from '../../setup/context'; | ||
|
||
describe('User router', () => { | ||
let caller: ReturnType<typeof userRouter.createCaller>; | ||
|
||
beforeEach(() => { | ||
caller = userRouter.createCaller(createInnerContext({})); | ||
}); | ||
|
||
it('should return all users', async () => { | ||
const users: User[] = [ | ||
{ | ||
id: '1', | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
emailVerified: new Date(), | ||
image: 'https://example.com/johndoe.png', | ||
}, | ||
{ | ||
id: '2', | ||
name: 'Jane Doe', | ||
email: '[email protected]', | ||
emailVerified: new Date(), | ||
image: 'https://example.com/janedoe.png', | ||
}, | ||
]; | ||
|
||
prismaMock.user.findMany.mockResolvedValue(users); | ||
|
||
await expect(caller.find.all()).resolves.toEqual(users); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { PrismaClient } from '@noodle/db'; | ||
import type { DeepMockProxy } from 'vitest-mock-extended'; | ||
import { mockDeep, mockReset } from 'vitest-mock-extended'; | ||
|
||
import { prisma } from '@noodle/db'; | ||
|
||
vi.mock('@noodle/db', () => ({ | ||
__esModule: true, | ||
prisma: mockDeep<PrismaClient>(), | ||
})); | ||
|
||
beforeEach(() => { | ||
mockReset(prismaMock); | ||
}); | ||
|
||
export const prismaMock = prisma as unknown as DeepMockProxy<PrismaClient>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@noodle/db", | ||
"version": "0.1.0", | ||
"private": true, | ||
"description": "Noodle's prisma database package", | ||
"license": "AGPL-3.0", | ||
"author": "Ahmed Elsakaan", | ||
"type": "module", | ||
"main": "./dist/index.js", | ||
"scripts": { | ||
"db:push": "prisma db push", | ||
"dev": "tsc -p tsconfig.build.json --watch", | ||
"lint": "eslint . --max-warnings 0 --report-unused-disable-directives", | ||
"lint:fix": "pnpm run lint --fix", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@prisma/client": "^4.16.2" | ||
}, | ||
"devDependencies": { | ||
"@noodle/tsconfig": "workspace:^", | ||
"eslint-config-noodle": "workspace:^", | ||
"prisma": "^4.16.2" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["jsonProtocol"] | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
directUrl = env("DIRECT_URL") | ||
} | ||
|
||
model Account { | ||
id String @id @default(cuid()) | ||
userId String | ||
type String | ||
provider String | ||
providerAccountId String | ||
refresh_token String? @db.Text | ||
access_token String? @db.Text | ||
expires_at Int? | ||
token_type String? | ||
scope String? | ||
id_token String? @db.Text | ||
session_state String? | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
@@unique([provider, providerAccountId]) | ||
} | ||
|
||
model Session { | ||
id String @id @default(cuid()) | ||
sessionToken String @unique | ||
userId String | ||
expires DateTime | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
} | ||
|
||
model User { | ||
id String @id @default(cuid()) | ||
name String? | ||
email String? @unique | ||
emailVerified DateTime? | ||
image String? | ||
accounts Account[] | ||
sessions Session[] | ||
} | ||
|
||
model VerificationToken { | ||
identifier String | ||
token String @unique | ||
expires DateTime | ||
@@unique([identifier, token]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"sourceRoot": "packages/db", | ||
"targets": { | ||
"build": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"commands": ["prisma generate", "tsc -p tsconfig.build.json"], | ||
"parallel": false, | ||
"cwd": "packages/db" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
export * from '@prisma/client'; | ||
|
||
const globalForPrisma = globalThis as { prisma?: PrismaClient }; | ||
|
||
export const prisma = | ||
globalForPrisma.prisma ?? | ||
new PrismaClient({ | ||
log: | ||
process.env['NODE_ENV'] === 'development' | ||
? ['query', 'error', 'warn'] | ||
: ['error'], | ||
}); | ||
|
||
if (process.env['NODE_ENV'] !== 'production') globalForPrisma.prisma = prisma; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": false, | ||
"outDir": "dist", | ||
"declarationMap": true | ||
}, | ||
"include": ["src/**/*.ts"], | ||
"exclude": ["src/**/*.test.ts", "src/**/*.spec.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "@noodle/tsconfig/base.json", | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"types": ["vitest/globals"] | ||
}, | ||
"exclude": ["./coverage/**/*"], | ||
"include": ["**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"extends": "@noodle/tsconfig/react.json", | ||
"compilerOptions": { | ||
"noEmit": true | ||
"noEmit": true, | ||
"types": ["vitest/globals"] | ||
}, | ||
"include": ["**/*.ts", "**/*.tsx"] | ||
} |
Oops, something went wrong.