-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3753e6
commit 6624354
Showing
15 changed files
with
118 additions
and
70 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
'*': 'prettier --check --ignore-unknown', | ||
'*.js': 'eslint --cache', | ||
'*.{js,ts}': () => 'npm run typescript:check', | ||
}; |
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,25 @@ | ||
import Prisma from '@prisma/client'; | ||
|
||
type ModelName = 'user' | 'message' | 'chat'; | ||
|
||
type PrismaModels = { | ||
user: Prisma.User; | ||
message: Prisma.Message; | ||
chat: Prisma.Chat; | ||
}; | ||
|
||
interface Crud { | ||
<T extends ModelName>( | ||
modelName: T | ||
): { | ||
read(id?: number): Promise<PrismaModels[T][]>; | ||
create(record: PrismaModels[T]): Promise<PrismaModels[T]>; | ||
update(id: number, record: Partial<PrismaModels[T]>): PrismaModels[T]; | ||
delete(id: number): PrismaModels[T]; | ||
}; | ||
} | ||
|
||
declare global { | ||
const db: Prisma.PrismaClient; | ||
const crud: Crud; | ||
} |
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,35 +1,41 @@ | ||
// @ts-nocheck | ||
const { PrismaClient } = require('@prisma/client'); | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
const crud = (model) => ({ | ||
async read(id) { | ||
if (!id) { | ||
return await prisma[model].findMany(); | ||
} | ||
return prisma[model].findUnique({ | ||
where: { id }, | ||
}); | ||
}, | ||
const crud = (modelName) => { | ||
const model = prisma[modelName]; | ||
if (!model) { | ||
throw new Error(`Model ${modelName} does not exist`); | ||
} | ||
|
||
async create(record) { | ||
return prisma[model].create({ | ||
data: record, | ||
}); | ||
}, | ||
return { | ||
async create(record) { | ||
return await model.create({ | ||
data: record, | ||
}); | ||
}, | ||
|
||
async update(id, record) { | ||
return prisma[model].update({ | ||
where: { id }, | ||
data: record, | ||
}); | ||
}, | ||
async read(id) { | ||
if (!id) return await model.findMany(); | ||
return await model.findUnique({ | ||
where: { id }, | ||
}); | ||
}, | ||
|
||
async delete(id) { | ||
return prisma[model].delete({ | ||
where: { id }, | ||
}); | ||
}, | ||
}); | ||
async update(id, record) { | ||
return await model.update({ | ||
where: { id }, | ||
data: record, | ||
}); | ||
}, | ||
|
||
async delete(id) { | ||
return await model.delete({ | ||
where: { id }, | ||
}); | ||
}, | ||
}; | ||
}; | ||
|
||
module.exports = crud; |
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
This file was deleted.
Oops, something went wrong.
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
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
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
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,13 +1,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"noEmit": true, | ||
"checkJs": true, | ||
"target": "ES2022", | ||
"module": "CommonJS", | ||
"lib": ["ES2022"], | ||
"esModuleInterop": true, | ||
"isolatedModules": true, | ||
"moduleResolution": "node", | ||
|
||
"emitDecoratorMetadata": false, | ||
"experimentalDecorators": false, | ||
|
||
"strict": true, | ||
"baseUrl": ".", | ||
"preserveWatchOutput": true, | ||
"allowJs": true, | ||
"noEmit": true, | ||
"skipLibCheck": true | ||
"alwaysStrict": true, | ||
"allowUnreachableCode": true, | ||
"allowUnusedLabels": true, | ||
"noImplicitAny": false, | ||
"noImplicitReturns": true, | ||
"resolveJsonModule": true, | ||
|
||
"declaration": true | ||
}, | ||
"include": ["*", "**/*"] | ||
"exclude": ["node_modules", "static"] | ||
} |