Robert Witchell
04/30/2021, 6:15 AMDanil Tikhii
04/30/2021, 7:06 AMconst conn = await pool.connect();
await conn.query("BEGIN");
const userRes = await conn.query("SELECT coins, ... , ... FROM "User" WHERE "id" = 'someId'" FOR UPDATE);
...
await conn.query("COMMIT");
Is there any way to do this? Don't wanna add pg library in project just for this functionality o.oLars Ivar Igesund
04/30/2021, 7:17 AMRobin
04/30/2021, 2:07 PMError: Error serializing `.urls[0].createdAt` returned from `getServerSideProps` in "/urls".
Reason: `object` ("[object Date]") cannot be serialized as JSON. Please only return JSON serializable data types.
Joey
04/30/2021, 5:28 PMwarn(prisma-client) Already 10 Prisma Clients are actively running.
and how do you ensure you only have one instance?
I am already doing;
//lib/prisma-client.ts
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
export default prisma
Then importing that instance and using it. Or do I have to explicitly have to disconnect
?Sebastian
05/01/2021, 5:54 AM// Console log
node[21175]: ../src/node_http_parser.cc:567:static void node::{anonymous}::Parser::Initialize(const v8::FunctionCallbackInfo<v8::Value>&): Assertion `args[3]->IsInt32()' failed.
1: 0x562789d0ab61 node::Abort() [node]
2: 0x562789d0abf7 [node]
3: 0x562789d26945 [node]
4: 0x562789f4ca37 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [node]
5: 0x562789f4d869 [node]
6: 0x562789f4de3f [node]
7: 0x562789f4e0e6 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
8: 0x56278a79d539 [node]
zsh: abort (core dumped) npm run dev
The code is sample from the website, for nextjs.
import { PrismaClient } from "@prisma/client";
import { NextApiHandler, NextApiRequest, NextApiResponse } from "next";
// The code:
const prisma = new PrismaClient()
async function main(){
const user = await prisma.user.create({
data:{
name: "test",
email: "<mailto:test@gmail.com|test@gmail.com>"
}
})
console.log(user)
prisma.$disconnect()
}
export default async (req: NextApiRequest, res: NextApiResponse, next: NextApiHandler)=>{
switch (req.method){
case 'POST':{
try{
await main().catch(err=>console.log(err)).finally(async()=>{
res.send("ok")
})
}
catch(err){
}
}
case 'GET':{
}
}
}
What went wrong?Sebastian
05/01/2021, 6:27 AMPrisma Studio is up on <http://localhost:5555>
node[6740]: ../src/node_http_parser.cc:567:static void node::{anonymous}::Parser::Initialize(const v8::FunctionCallbackInfo<v8::Value>&): Assertion `args[3]->IsInt32()' failed.
Dog
05/01/2021, 9:14 AMDog
05/01/2021, 9:14 AMCarlos
05/01/2021, 12:44 PMprisma.posts.findUnique_({......}).then().catch()
Joakim Repomaa
05/02/2021, 11:47 AMJoakim Repomaa
05/02/2021, 11:50 AMJoakim Repomaa
05/02/2021, 11:51 AMJoakim Repomaa
05/02/2021, 11:52 AMPATCH /post
i'd expect to be able to do something like prisma.post.update({ where: { id: params.id, user: { id: context.currentUser.id } }, ... })
stephan levi
05/02/2021, 4:05 PMAlexis
05/03/2021, 3:35 AMRole.findOne({
raw: true,
where: {
guild: this.guild.id,
channel: message.channel.id,
message: message.id,
pairs: {
[Op.contains]: [{ emoji }],
},
},
});
// Is this a thing in Prisma? "pairs" in an array of objects which has an emoji prop (along with other props)
Paul
05/03/2021, 9:29 AMmodel DamFiles {
id Bytes @id @db.Binary(26)
...
createdAt DateTime @default(now())
updatedAt DateTime? @updatedAt
deletedAt DateTime?
// relations
type DamFileTypes @relation(fields: [typeId], references: [id])
typeId Bytes @db.Binary(26)
mime DamFileMimeTypes @relation(fields: [mimeId], references: [id])
mimeId Bytes @db.Binary(26)
user User @relation(fields: [userId], references: [id])
userId Bytes @db.Binary(26)
DamImages DamImages[]
DamFileTags DamFileTags[]
DamImageColors DamImageColors[]
}
When I do a query, I get the type, mime, user relations by using include. When I include the DamImages, DamFileTags and DamImageColors. I don't see them appearing in the result object.
My query:
const query = await db.damFiles.findMany({
where: {
parentId: queryParams.parentId,
deletedAt: null,
},
include: {
user: {
},
mime: {
},
type: {
},
DamFileTags: {
},
DamImageColors: {
},
DamImages: {
},
},
})
Am I right in saying. The Dam tables aren't getting anything due to having a where clause on them internally using parentId ? Thanks
Note: I have pulled out the select statements for brevity.Danil Tikhii
05/03/2021, 3:48 PMconst conn = await pool.connect();
await conn.query("BEGIN");
const userRes = await conn.query("SELECT coins, ... , ... FROM "User" WHERE "id" = 'someId'" FOR UPDATE);
...
await conn.query("COMMIT");
Is there any way to do this? Don't wanna add pg library in project just for this functionality o.oStasi Vladimirov
05/03/2021, 11:44 PMQuery 1: SELECT * FROM `Schema1`.`Requests`
and
Query 2: SELECT * FROM `Schema2`.`Accounts`
Mitchell Amihod
05/04/2021, 2:15 AMWhile we're still killing the child processes, after the beforeExit hook has been executed, we're not killing the current process anymore, if there are other listeners on the signals, like SIGINT.
For context, i came across this when looking into graceful shutdowns with nestjs + prisma, with prisma swallowing up the sigtermMitchell Amihod
05/04/2021, 2:18 AMMitchell Amihod
05/04/2021, 2:57 PMUlysse Tallepied
05/04/2021, 4:37 PMStasi Vladimirov
05/05/2021, 1:42 AMprisma.$use(async (params, next) => {
if (
whereActions.includes(params.action) &&
params.model &&
prisma[params.model].prototype.hasOwnProperty('tenantId')
) {
params.args.where.tenantId = requestTenantId
}
const result = await next(params)
return result
})
the main question is how to do this part:
prisma[params.model].prototype.hasOwnProperty('tenantId')
or in other words:
How to check, if an abstract model (table) contains a specific property (column)?Natalia
Hector
05/05/2021, 5:09 PMinclude
option?Nitzan
05/05/2021, 6:02 PMWilson
05/05/2021, 6:03 PM*Error:* Failure during a migration command: Generic error. (error: The field .... on model .... already exists in this Datamodel. It is not possible to create it once more.)
but my coworker is able to migrate correctly, what am i missing?Ron Mizrahi
05/05/2021, 8:04 PMJonathan Romano
05/06/2021, 1:16 AMconst selectPublicFields = {...}
async findOne(
{ id, email }: { id?: number; email?: string },
selectPrivateFields: { email?: boolean } = {}
) {
return this.prisma.user.findUnique({
select: {
...selectPrivateFields,
...selectPublicUserFields
},
where: { id, email },
});
}
The return type winds up only including id, createdAt, and name, regardless of what I pass to includePrivateFields. Is there a way to type this function so that the caller of findOne will get the correct return type based on the additional fields passed in includePrivateFields?