Kevin Reed
09/16/2022, 11:41 PMDATABASE_URL
) I'm able to connect no problem, but when I try and use my external IPv4, that I have port forwarded, it fails to connect. Is there something that I'm missing? I'm trying to cut down on DB hosting costs.Pranav Sathyanarayanan
09/17/2022, 3:31 AMpgbouncer=true
flag on our connections. However our application still seems to be creating a connection pool of 2n+1
(so in our case 5 as these are 2 core machines) on our GCP Cloud Run applcation. I wanted to know:
1. What is the recommendation w.r.t to connection pooling in the application (Prisma) when we have pgBouncer configured. I was under the assumption that the application shouldn't pool connections at all and should opt rather to simply "request" a new connection (or create a new one) per query.
2. What happens if we set the connection_limit
to 0? Does this just disable application side pooling? The recommendation seems to be setting it to "1" however our intended behavior is that Prisma defers entirely to pgbouncer to supply connections on demand.
3. Prisma chunks large / complex queries into a series of SELECT statements one after the other. How does this behavior impact settings + usage of pgbouncer?
4. I assumed setting pgbouncer=true
should have disabled the client side application pool totally. I am still seeing (however) "timeouts" fetching a new connection with connection limit printing 5. Is that expected?Samrith Shankar
09/17/2022, 4:09 AMerror: Error validating datasource `db`: the URL must start with the protocol `mysql://`.
Now the thing is my DATABASE_URL
is present in my Lambda configuration and when I log it, it does even print it. Don’t know why this is happening.. any idea?
Full error message:
"Runtime.UnhandledPromiseRejection: Error: error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.",
" --> schema.prisma:3",
" | ",
" 2 | provider = \"mysql\"",
" 3 | url = env(\"DATABASE_URL\")",
" | ",
"",
"Validation Error Count: 1",
" at process.<anonymous> (file:///var/runtime/index.mjs:1131:17)",
" at process.emit (node:events:527:28)",
" at emit (node:internal/process/promises:140:20)",
" at processPromiseRejections (node:internal/process/promises:274:27)",
" at processTicksAndRejections (node:internal/process/task_queues:97:32)"
Client version: 3.15.2
Error message code: P1012Javier Sebastián Fernández
09/17/2022, 12:12 PMimport { PrismaClient } from '@prisma/client';
let prisma: PrismaClient;
if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient();
} else {
if (!(global as any).prisma) {
(global as any).prisma = new PrismaClient();
}
prisma = (global as any).prisma;
}
export default prisma;
I've have also tried this:
import { PrismaClient } from '@prisma/client';
declare global {
// allow global `var` declarations
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}
export const prisma =
global.prisma ||
new PrismaClient({
log: ['query'],
});
if (process.env.NODE_ENV !== 'production') global.prisma = prisma;
This is the error that I am getting:Jarupong
09/18/2022, 3:19 AMRichard
09/18/2022, 8:18 AMapi/register
endpoint
- which runs a multi-document transaction in my mongodb database (updateMany
)
The Issue I'm encountering:
If two calls to that endpoint are made quickly, the latter one fails because the former's transaction in mongoDB isn't done yet. (see screenshot)
(continues in thread)Vasily Zorin
09/18/2022, 10:18 AMKenny Tran
09/18/2022, 11:54 AMtake: N?
await prisma.record.findMany({
take: N
})
Theo Letouze
09/18/2022, 12:58 PMRichard
09/18/2022, 2:30 PMargs
two levels up?
// in user.controller.ts
const getUser => {
const user = this.userService.findFirst({where: { id: "1" }, include: { childrenField: true } })
user
//ˆ? type is `User` ❌
// what I want: `User & { childrenField: ChildenField }`
}
// in user.service.ts file...
async findFirst(args: Parameters<typeof this.userRepository.findFirst>[0]) {
return await this.userRepository.findFirst(args);
}
// in user.repository.ts file...
const findFirst = async (args) => {
return await this.prisma.user.findFirst(args);
}
Ridhwaan Shakeel
09/18/2022, 4:25 PM/app/node_modules/.prisma/client/index.js:3
throw new Error(
^
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
In case this error is unexpected for you, please report it in <https://github.com/prisma/prisma/issues>
at new PrismaClient (/app/node_modules/.prisma/client/index.js:3:11)
at Object.<anonymous> (/app/server/data/index.js:3:16)
at Module._compile (node:internal/modules/cjs/loader:1119:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
at Module.load (node:internal/modules/cjs/loader:997:32)
at Module._load (node:internal/modules/cjs/loader:838:12)
at Module.require (node:internal/modules/cjs/loader:1021:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/app/server/routes/index.js:39:5)
at Module._compile (node:internal/modules/cjs/loader:1119:14)
Why does this happen sometimes?
prisma database is not empty but sometimes requires a prisma generateCraig Haseler
09/18/2022, 10:49 PMlet procedure= "pbk_Chart_Data_Get"
let params = [{name: "PARSID", value: "1024"}]
return prisma.$queryRaw`${procedure} ${params[0].name} = ${params[0].value};`;
Here's what I get back from Prisma/SQL
prisma:error @P2 is not a parameter for procedure pbk_Chart_Data_Get.
prisma:query @P1 @P2 = @P3;
@P1 @P2 = @P3; ["pbk_Chart_Data_Get","@PARSID",1033]
But I know that SP takes a parameter called PARSID which is an int. So I'm not sure how to accomplish this.
Even if I can, I'm not sure how to expand this to an arbitrary number of stored proc parameters.Raphael Etim
09/19/2022, 5:38 AMArpan Bagui
09/19/2022, 7:25 AMTheo Letouze
09/19/2022, 7:41 AMRichard
09/19/2022, 9:40 AMtsc
to have the same output as VSCode's TypeScript server?
Somehow, the compilation isn't able to pick up the include
return type from prisma while VSCode is.
❌
src/auth/auth.service.ts:293:13 - error TS2339: Property 'tokenSet' does not exist on type 'User'.
293 const { tokenSet, ...user } = userDatabase;
~~~~~~~~
Here's the typescript signature of my function:
async findFirst<T extends Prisma.UserFindFirstArgs>(
args: Prisma.SelectSubset<T, Prisma.UserFindFirstArgs>,
) {
const user = await this.prisma.user.findFirst(args);
if (!user) throw new NotFoundException('User not found!');
return user;
}
whereas in vscode, the type is inferred correctly.. 🤔ven v
09/19/2022, 10:22 AMven v
09/19/2022, 2:02 PMJoey
09/19/2022, 2:32 PMmodel Coordinate {
direction String // NORTH | SOUTH | EAST | WEST
x Float
y Float
id String @id @default(cuid())
}
I know I can count how many records have one value, say ‘SOUTH’ for instance, but is there any way, in one call, to count how many records have north, how many have south, how many have east, and how many have west?Rob Hoskins
09/19/2022, 2:59 PMmodel User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
Like Like[]
Playlist Playlist[]
}
model Playlist {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
likeCount Int?
type PlaylistType
url String
name String?
description String?
author String?
tags Tag[]
submittedBy User? @relation(fields: [userId], references: [id])
likes Like[]
userId String?
}
model Like {
id String @id @default(cuid())
createdAt DateTime @default(now())
user User[]
playlist Playlist[]
}
Rob Hoskins
09/19/2022, 3:50 PMTerada
09/19/2022, 4:41 PMRidhwaan Shakeel
09/19/2022, 5:57 PMKyle Hayes
09/19/2022, 6:10 PMМовсар Халахоев
09/19/2022, 6:16 PMEmanuele Ricci
09/19/2022, 8:55 PMconst effects = await prisma.transactionEffect.findMany({
where: {
assetBalance: {
wallet: {
id: wallet?.id,
},
asset: {
symbol: assetBalance?.asset?.symbol,
},
},
},
orderBy: {
transaction: {
blockNumber: 'desc',
},
},
include: {
transaction: true,
// here I would like to include assetPrice
// assetPrice has not a connection directly with transactionEffect
// is it possible to include it even if there's not a releationship but I can say
// load the price where assetId = XXX and timestamp = XYZ?
},
});
Emanuele Ricci
09/19/2022, 9:01 PMconst effects = await prisma.transactionEffect.findMany({
where: {
assetBalance: {
wallet: {
id: wallet?.id,
},
asset: {
symbol: assetBalance?.asset?.symbol,
},
},
},
orderBy: {
transaction: {
blockNumber: 'desc',
},
},
include: {
transaction: true,
assetBalance: {
include: {
asset: {
include: {
assetPrice: {
where: {
blockDate: // must be equal to transaction.timestamp (datetime) formatted as MM/dd/yyyy
}
}
}
}
}
}
},
});
Rob Hoskins
09/19/2022, 9:09 PMmodel User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
Playlist Playlist[]
Like Like[]
}
model Playlist {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
likeCount Int?
type PlaylistType
url String
name String?
description String?
author String?
tags Tag[]
submittedBy User? @relation(fields: [userId], references: [id])
likes Like[]
userId String?
}
model Like {
id String @id @default(cuid())
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id])
userId String
playlist Playlist @relation(fields: [playlistId], references: [id])
playlistId String
@@unique([userId, playlistId])
}
const newLike = { userId: 'cl883tgpm0079x4u5ivj6bzv9', playlistId: 'cl86l256l00935cu59fv08pc3' }
const result = await prisma.playlist.update({
where: {
id: 'cl86l256l00935cu59fv08pc3'
},
data: {
likeCount: { increment: 1 },
likes: {
upsert: {
create: newLike,
update: newLike
}
},
},
include: {
likes: true,
tags: true
}
})
console.log(result)
Ryan Roline
09/20/2022, 3:28 AMStevieW
09/20/2022, 8:34 AMimport { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
const allPosts: Post[] = await prisma.post.findMany()
Each time this is called, what happens to the prisma client? Does it auto disconnect when done, and next time it's called a new one is created (then closed) or will I end up with 1000's of these open and running in the background?
If so, do I need to just create one and use that all the time? How does that work if it has to handle 1000's of requests at once?
I guess I'm just after a little guidance on how best to approach. I get these are likely basic questions! I'm moving over from Python / Django and trying to get my head around things. Thanks!