Skip to content

Commit

Permalink
feat(client): middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Jul 16, 2020
1 parent 31a2cc9 commit 2052d79
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 316 deletions.
40 changes: 2 additions & 38 deletions src/packages/client/fixtures/blog/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,9 @@ const prisma = new PrismaClient({
})

async function main() {
// const result = await prisma.user.aggregate({
// avg: {
// age3: true,
// },
// sum: {
// age: true,
// },
// min: {
// age: true,
// },
// max: {
// age: true,
// },
// count: true,
// })
// const result = await prisma.user.count({
// take: 10,
// })
// const result = await prisma.user.aggregate({
// avg: {
// age: true
// },
// max: {
// age: true
// },
// sum: {
// age: true
// },
// min: {
// age: true
// },
// count: true
// })
// result.count
// result.avg.age
// console.log(result)
const res = await prisma.user.findMany({
distinct: ['age'],
})
distinct: ['2age'],
} as any)
console.log(res)
prisma.disconnect()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ module.exports = async () => {
const userPromise = prisma.user.findMany()
await userPromise
// @ts-ignore
const perfResults = userPromise._collectTimestamps.getResults()
if (Object.keys(perfResults).length === 0) {
throw Error('measurePerformance is enabled but results object is empty')
}

await prisma.disconnect()

Expand Down
5 changes: 0 additions & 5 deletions src/packages/client/src/__tests__/runtime-tests/blog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = async () => {
const db = new PrismaClient({
errorFormat: 'colorless',
__internal: {
measurePerformance: true,
hooks: {
beforeRequest: (request) => requests.push(request),
},
Expand Down Expand Up @@ -53,10 +52,6 @@ module.exports = async () => {
const userPromise = db.user.findMany()
await userPromise
// @ts-ignore
const perfResults = userPromise._collectTimestamps.getResults()
if (Object.keys(perfResults).length === 0) {
throw Error('measurePerformance is enabled but results object is empty')
}

await db.disconnect()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ module.exports = async () => {
const allResults = []
const engineResults = []

db.use('all', async ({ params, fetch }) => {
db.use('all', async (params, fetch) => {
const result = await fetch(params)
allResults.push(result)
return result
})

db.use('engine', async ({ params, fetch }) => {
db.use('engine', async (params, fetch) => {
const result = await fetch(params)
engineResults.push(result)
return result
Expand Down
3 changes: 1 addition & 2 deletions src/packages/client/src/generation/TSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ declare class PrismaClientFetcher {
private readonly debug;
private readonly hooks?;
constructor(prisma: PrismaClient<any, any>, debug?: boolean, hooks?: Hooks | undefined);
request<T>(document: any, dataPath?: string[], rootField?: string, typeName?: string, isList?: boolean, callsite?: string, collectTimestamps?: any): Promise<T>;
request<T>(document: any, dataPath?: string[], rootField?: string, typeName?: string, isList?: boolean, callsite?: string): Promise<T>;
sanitizeMessage(message: string): string;
protected unpack(document: any, data: any, path: string[], rootField?: string, isList?: boolean): any;
}
Expand Down Expand Up @@ -1160,7 +1160,6 @@ export declare class Prisma__${name}Client<T> implements Promise<T> {
private _isList;
private _callsite;
private _requestPromise?;
private _collectTimestamps?;
constructor(_dmmf: DMMFClass, _fetcher: PrismaClientFetcher, _queryType: 'query' | 'mutation', _rootField: string, _clientMethod: string, _args: any, _dataPath: string[], _errorFormat: ErrorFormat, _measurePerformance?: boolean | undefined, _isList?: boolean);
readonly [Symbol.toStringTag]: 'PrismaClientPromise';
${indent(
Expand Down

0 comments on commit 2052d79

Please sign in to comment.