Wingy
11/27/2021, 5:53 AMBenjamin Smith
11/29/2021, 2:36 AMgenerator myThing {
provider = "node ./dist/index.js"
config = `
my config goes here
it is multiple lines
`
}
Or like this if necessary:
generator myThing {
/**
my config goes here
it is multiple lines
*/
provider = "node ./dist/index.js"
}
But I can't figure out a way to do it. Right now the best option seems to be to have a separate docstring comment for each line, but that gets annoying to type if there's a lot of lines:
generator myThing {
/// my config goes here
/// it is multiple lines
provider = "node ./dist/index.js"
}
Mischa
11/29/2021, 11:33 AMON CONFLICT ...
for upserts?Anton Reindl
12/01/2021, 2:31 PMareas
and epics
. An area
has many epics
and they are related through an areaId
on epics. I have a controller method area/<area-uid>/epics
in my API.
What’s the best way to get all epics for a given area ?
I tried two ways:
1. Two function calls
const area = await this.findOne(uid)
return this.prisma.epic.findMany({ where: { area } })
--> this creates two independent SQL quereies
2. One function call
return (await this.prisma.area.findUnique({ where: { uid }, select: { epics: true } }))['epics']
Works, but feels quirky.
---
Is there a better solution? Like a simple right join?
Thanks for feedback. I am sure this is a rookie thing.
Cheers
Antonnikos l
12/01/2021, 2:35 PMreturn this.prisma.test.findUnique({
where: {
id: params.id,
},
include: {
test1: {
include: {
test2: transformationHelper()
}
}
}
nikos l
12/01/2021, 2:36 PMShane
12/02/2021, 1:50 PMcreateMany
-- but there is a chance that some rows will duplicate on unique constraint. In those cases I'd like it to just be graceful eg. skip that row or update etc.
The best idea i have is to run many concurrent upsert operations, but this could be very inefficient with thousands of rows.Shane
12/02/2021, 1:50 PMShane
12/02/2021, 1:52 PMjames tan
12/02/2021, 2:35 PMMischa
12/02/2021, 6:37 PMlog: ["query"]
is nice and helpful to print out the SQL queries, is there a way to print out the values along with the placeholders when it executes the query?Aaron Waller
12/03/2021, 6:31 AMMischa
12/03/2021, 4:01 PMGarrett Tolbert
12/04/2021, 3:33 AMupsert()
method as a findorCreate
implementation, I get { count: 0 }
. This is only happening when a user is already in the database. Can someone tell me why this is happening? Below is a snippet of the method call.
const user = await prisma.user.upsert({
where: { email: profile.emails[0].value },
update: {},
create: {
email: profile.emails[0].value,
name: profile.displayName,
},
});
Luke Carr
12/05/2021, 5:08 PMRyan O'Shea
12/06/2021, 1:45 PM?
this works with a relation, or in general.
I have a model Issue
with a field assignedTo
that takes a relation User?
as an optional field.
model Issue {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
title String
description String
createdBy User @relation(name: "createdByUser", fields: [createdById], references: [id])
createdById Int
assignedTo User? @relation(name: "assignedTo", fields: [assignedToId], references: [id])
assignedToId Int?
}
However, I can't seem to find a way to write a query to create
or update
that doesn't demand an Int
at assignedTo
without the query failing.
For example, the query below won't work unless there is an Int
at input.isssue.assignedTo.id
.
const newIssue = await db.issue.create({
data: {
title: input.issue.title,
description: input.issue.description,
createdBy: {
connect: {
id: ctx.session.userId,
},
},
assignedTo: {
connect: {
id: Number(input.issue.assignedTo.id),
},
},
},
})
I tried passing in null
and undefined
directly but both are rejected by the schema.
Or should there be separate create and update queries for optional fields?
if(input.issue.assignedTo.id) { createIssueWithAssignedUser()}
else {createIssue()}
Matthew Hinton
12/06/2021, 3:52 PMField does not exist on enclosing type.
I am using prisma version 3.6 with this schema definition.
model KeepAlives {
id Int @id @default(autoincrement())
tfield String
seededAt DateTime @default(now())
@@map("keep_alives")
}
I get the error when trying to execute this line: *const* keepAliveArr *=*
*await* prisma.keepAlives.findMany()
.Lukáš Stuchlík
12/06/2021, 8:36 PMra-data-prisma
plugin for React Admin (to connect with Nexus backend) does a thing where you supply new and previous data, it compares them field-wise and only sends a GQL request with setting only new values.
So if I have an object { id: 1, name: 'John', lastName: 'Doe' }
and I pass a new object { id: 1, name: 'John', lastName: 'Smith' }
it automatically sends a query like { lastName: { set: 'Smith' } }
and doesn't touch any unchanged fields.
Do we have anything like this in Prisma? Or is the "unnecessary update" overhead negligible?james tan
12/08/2021, 7:02 AMawait this.prisma.invoiceItems.create(
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(ServerError { code: 3140, message: "target: unigate.-.primary: vttablet: (errno 3140) (sqlstate 22032) (CallerID: unsecure_grpc_client): Sql: \"insert into InvoiceItems(id, invoice_id, item, paid, accepted_coins, createdAt, currency, updatedAt, amount, paid_amount) values (:v1, :v2, :v3, :v4, :v5, :v6, :v7, :v8, :v9, :v10)\", BindVars: {}", state: "22032" })) })
Okamikun
12/09/2021, 2:53 AM2021-12-09T02:11:42.536Z 38e30598-f091-5333-936d-5fb3975e21d6 Task timed out after 62.06 seconds
Is that normal behavior or do I need to change my settings so that an error is thrown by Prisma?
This is my table definition:
model tbl_Log {
id Int @id @default(autoincrement())
type LogType
message String?
createdAt DateTime
user tbl_User @relation(fields: [userId], references: [id])
userId String
orderSnapshot Json
amount Float
}
And I am creating the DB entry via:
await prisma.tbl_Log.create({
data: {
type: log.type!,
message: log.message!,
createdAt: log.createdAt!,
userId,
orderSnapshot: log.orderSnapshot!,
amount: log.amount ?? 0,
},
});
If amount
is null
, the Lambda function hangs at this step, if amount
has a number
it works (with 0, too).Yaakov
12/09/2021, 3:56 PMJonathan Gotti
12/10/2021, 10:41 AMfunction getPost(postId: string, includeDef: Prisma.PostInclude) Promise<Post> {
const include = {
...includeDef,
comments: true
}
return await this.prisma.post.findUnique({
where: {id: postId},
include
})
}
Jonathan Gotti
12/10/2021, 10:45 AMconst post = getPost(postId, {owner: true})
// trying to do something with post.owner will cause typescript to complain that property owner doesn't exist
Jonathan Gotti
12/10/2021, 10:45 AMVladislav
12/10/2021, 6:16 PMMischa
12/14/2021, 2:05 PMRoryl
12/17/2021, 9:57 PMjuanloco
12/19/2021, 3:35 PMJsonObject
, E.G: see below. How would I do this if the model includes dates? I am currently getting an error due to a type mismatch since a JSON object doesn’t accept date values? but a date should just be parsed to a string I believe, do I need to do this manually so TS won’t complain?
model User { // user schema here}
import { User } from '@prisma/client';
const myObject: User = prisma.user.findUnique(// query here);
prisma.modelWithJsonField.create({
data: { jsonField: myObject }
});
Jay Bell
12/23/2021, 4:53 PMbinaryTargets = ["native", "linux-musl", "linux-arm-openssl-1.1.x"]
but then once we deploy to AWS we get
Error: Unknown PRISMA_QUERY_ENGINE_LIBRARY undefined. Possible binaryTargets: darwin, darwin-arm64, debian-openssl-1.0.x, debian-openssl-1.1.x, rhel-openssl-1.0.x, rhel-openssl-1.1.x, linux-arm-openssl-1.1.x, linux-arm-openssl-1.0.x, linux-musl, linux-nixos, windows, freebsd11, freebsd12, openbsd, netbsd, arm, native or a path to the query engine library.
We are using Prisma 3.0.1, I know this is older we cannot upgrade (without some more investigtion) because of this issue
https://github.com/prisma/prisma/issues/10512
We have multiple prisma schemas in our Nx repo and upgrading to the newest prisma seems to break them. cause it is looking in a hard coded spot for the schema.
Ideas?Sabin Adams
12/23/2021, 9:37 PMconst entityStates = await this.prisma.entityState.findMany({
select: { id: true, entityTypeID: true },
where: {
name: state
}
})
const entityTypes = await this.prisma.entityType.findMany({
select: { id: true },
where: {
name: 'Enrollment',
id: { in: entityStates.map( state => state.entityTypeID ) }
}
})
The logic I'm looking for would look something like this
const entityTypes = await this.prisma.entityType.findMany({
select: { id: true },
where: {
name: 'Enrollment',
EntityStates: {
where: {
name: state
}
}
}
})