Alban Kaperi
10/20/2022, 2:05 PMAlban Kaperi
10/20/2022, 2:05 PMDan Calise
10/20/2022, 2:45 PM$queryRaw
does not work?
code: 'P2010',
clientVersion: '4.3.1',
meta: { code: 'N/A', message: 'N/A' },
I just get N/A for code/messageZack Chapple
10/20/2022, 3:40 PMDavid Stotijn
10/20/2022, 6:13 PMselect * from "foobar"
where ("foo", "bar", "baz") > ('lorem', 'ipsum', 'dolor')
Sebastian Gug
10/20/2022, 6:41 PMElias Wambugu
10/20/2022, 7:48 PMprisma migrate dev
Migration `20220609015525_test` failed to apply cleanly to the shadow database.
Error:
db error: ERROR: type "citext" does not exist
Ray Tiley
10/20/2022, 10:38 PMRay Tiley
10/20/2022, 10:38 PMTakeo Kusama
10/21/2022, 4:45 AM@db.Date
(at least postgresql) type currently inevitably go wrong if using the other timezone not UTC on the server due to two problems.
First, prisma canât keep timezone information with cut off @db.Date
when storing the data. Further worse, it uses UTC after conversion, thus if user intend to input date as userâs local timezone, it must be forward off by one day and itâs impossible to repair them if contaminating with correct date due to lack of offset by the cut off when local timezone is earlier UTC time.
Second, when restoring javascriptâs date object, it must need offset because db stores UTC: 000000 time. Itâs not identical date by timezone, then users must convert it to their timezone 000000. Otherwise, the server with local timezone later UTC force the date forward off by one day. But prisma client seem not implement this.
The two problems leads to 100% bug if using any timezone except for UTC and dangerous if users donât know that. I suggest simple patch to adjust in the issue in repo. This patch can be used as long as user db stores date as utc: 000000 (though when not cutoff time or prisma will support db stores local time, the logic needs to be skipped).
I can fix it with patch only in my code, but this is prismaâs bug, and no one can use appropriately @db.Date
without the patch or living in GMT. If prisma can patch this, the patch in my code must be removed. So can I have the way to tell prisma dev team the fact and ask to fix it?nikandroid2013
10/21/2022, 8:28 AMAnton Johansson
10/21/2022, 12:04 PMMarek BrzeziĹski
10/21/2022, 2:11 PMhome
and away
teams in Match
model. Is it even possible to have a relation field that keeps relations to 2 different fields on the other model?
model Team {
id Int @id @unique
name String @unique
teamName String
locationName String
website String
League League @relation(fields: [leagueId], references: [id])
leagueId Int
Match Match[] // <- THIS ONE IS PROBLEMATIC
}
model Match {
id String @id @default(cuid())
apiId String
gameDate DateTime
season String
League League @relation(fields: [leagueId], references: [id])
leagueId Int
homeTeam Team @relation("Home team", fields: [homeTeamId], references: [id])
awayTeam Team @relation("Away team", fields: [awayTeamId], references: [id])
homeTeamId Int
awayTeamId Int
}
Richard Kaufman-LĂłpez
10/21/2022, 6:18 PMconst userSelect: Prisma.UserSelect = {
id: true,
name: true,
}
const user = await prisma.user.findUnique({
where: { id: 1 },
select: userSelect
})
const posts = await prisma.post.findMany({
where: { authorId: 1 },
select: {
id: true,
user: {
select: userSelect
}
}
})
However, this isnât working properly. When using userSelect
in the queries, the queries know userSelect
is of the expected type (Prisma.UserSelect
), but it doesnât know which fields have actually been selected. This ends up typing both user
and posts.user
to be {}
.
A different approach would be to instead write userSelect
like this:
const userSelect = {
id: true,
name: true,
} as const;
That works in the query and correctly types the query result. However, now I lose type safety and autocomplete in the definition of userSelect
.
Can someone think of a solution that would work correctly in the query select property, the query result, and that would also allow type safety in the definition of the select object?Loren Siebert
10/21/2022, 7:36 PMconst a = client.accounts.findFirst(âŚ)
, is there a way I can find out the table name Accounts
from a
? Something like a.tableName
? Sort of related to this issue.ChanceAlert
10/21/2022, 10:46 PMprofile
as well as cognitoUser
. I learned that in order to do this, I have to add an onDelete: Cascade
property to the @relation
of the dependent table. Now, my schema looks as the following:
model User {
id String @id @default(uuid())
cognitoUser CognitoUser? @relation(fields: [cognitoUserSub], references: [sub])
profile Profile @relation(fields: [profileId], references: [id])
}
model CognitoUser {
sub String @id
user User?
}
model Profile {
id String @id @default(uuid())
user User?
}
I now have three questions:
1. I want to do the cascading deletes. Did I choose the wrong side (table) to store the foreign key for both profile
and cognitoUser
?
2. If I did choose the wrong side(s), how can I switch the foreign key to the Profile
and CognitoUser
tables?ChanceAlert
10/21/2022, 10:50 PMSongkeys
10/22/2022, 2:59 PMNoAction
seems useful to me.David Hancu
10/23/2022, 10:08 AM@Unsupported
along with @default(dbgenerated())
to create a TSVECTOR
. This method works great, because it edits the migration to generate the TSVECTOR
using GENERATED ALWAYS AS
. But, whenever I try to use this migration, Prisma decides out of the blue to create a migration with just one faulty line that causes an error:
-- AlterTable
ALTER TABLE "<Table>" ALTER COLUMN "<Column>" DROP DEFAULT;
And of course, because it is a generated column, I get this error:
Database error code: 42601
Database error:
ERROR: column "<Column>" of relation "<Table>" is a generated column
HINT: Use ALTER TABLE ... ALTER COLUMN ... DROP EXPRESSION instead.
I've seen the GitHub issues for this and none have fixed my issue. Is there any workaround for this?Jinhyuck Cha
10/23/2022, 11:01 AMthis is my schema
model author {
id String @id()
first_name String
second_name String
description String?
@@unique([first_name, second_name])
}
this is what i want to use in query
prisma.datasets.delete({
where: {
id: datasetId,
first_name: 'kim'
}
But in real, i must put into second_name in where clause
prisma.datasets.delete({
where: {
id: datasetId,
first_name_second_name: {
first_name: 'kim',
second_name: 'sonny'
}
}
})
I want to partially use where clause in update, delete api!!!!Rafo
10/23/2022, 11:29 PMJinhyuck Cha
10/24/2022, 1:14 AMfindFirst()
API?Jinhyuck Cha
10/24/2022, 2:05 AMfindUniqueOrThrow()
I try to use it in try-catch clause
But the error code not show!!!
it just weired, cause the docs said they throw error code and message!
this is my code
try {
const dataset = await this.prisma.datasets.findUniqueOrThrow({
where: {
tenant_id: tenantId,
id: datasetId,
},
});
} catch (e) {
console.log(e);
if (e instanceof Prisma.PrismaClientKnownRequestError) {
prismaQueryFailedError(e);
}
throw e;
}
this is error code
NotFoundError: No datasets found
at /Users/chacha/workspace/dingo/apps/core-api/node_modules/@prisma/client/runtime/index.js:30377:13
Chris Tsongas
10/24/2022, 3:19 AMDavid Van Isacker
10/24/2022, 6:10 AMReo Yamashita
10/24/2022, 8:48 AMmodel User {
id String
firstName String @db.VarChar(100)
lastName String @db.VarChar(100)
teams TeamMember[] @relation(name: "user")
updated_at String
@@id([id])
}
model Team {
id String @default(uuid()) @db.Uuid
name String @db.VarChar(30)
members TeamMember[] @relation()
@@id([id])
}
model TeamMember {
id String @default(uuid()) @db.Uuid
user User @relation(name: "user", fields: [userId], references: [id])
team Team @relation(fields: [teamId], references: [id])
userId String
teamId String @db.Uuid
role TeamRole @default(Admin)
assignedAt String
@@id([userId, teamId])
}
I want users to update a team. especially , Only user who belongs to the team can update the team.
how should I code with Prisma?David Hancu
10/24/2022, 10:49 AM@default
, allowing you to create JS functions that will be ran when a new row is inserted to allow you to customize the ID structure. (The way this will work is that the function will take the DMMF data as an argument and you are expected to return a result. To make this clearer, a proposal will be created soon, so stay tuned for that.)
⢠Add a flag which runs migrations with CREATE TABLE UNLOGGED
instead of CREATE TABLE
(will be implemented under --unlogged-tables
)
⢠Prisma.EnumName
counterpart for Prisma.ModelName
, to facilitate development by providing a list of enums currently available
⢠Allow refined TypeScript types for fields. For instance you might want to allow only a specific subset of Strings on a field. (Since this feature is more complex, a proposal will be created for it.) This feature is inspired from this issue: https://github.com/prisma/prisma/issues/15742
That is all for this release, I've filtered out what people wanted and have scheduled a few features for v1.5.0 as well. But that list isn't finished yet and it's going to have to wait until this version is released, so let me know what else you'd like to see in Prisma.shahrukh ahmed
10/24/2022, 3:28 PMmodel User {
id Int @id @default(autoincrement())
uuid String @default(cuid())
}
model Posts{
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
id Int @id @default(autoincrement())
@@unique([userId, id])
}
My question is, how can I filter an post with Post id
and user uuid?
I know about the userId_id method. Would like guidance on how to include uuid
in some instances. .
where: {
userId_id: {
id: parseInt(id),
userId
}
}
Jenn Junod
10/24/2022, 6:41 PMtweetytag/index.js /
if I run node index.js
whatever I have twitterHandle:
equal to, it inputs into the database.... RN it's (edited)
async function main() {
await prisma.twitterHandle.create({
data: {
twitterHandle: '@jennjunod',
},
})
const alltwitterHandles = await prisma.twitterHandle.findMany({
})
console.dir(alltwitterHandles, { depth: null })
}
so of course I don't always want it to be my name, I want it to be whatever what input in the form
tweetytag/next-forms-app/pages/index.tsx
let's me enter the twitter name and on line 35 i can see that's cause alert(Is this your Twitter handle? ${(form.twitterHandle.value)})
sooooo I would think if I can get tweetytag/index.js /
to read form.twitterHandle.value
in this code instead of '@jennjunod' it would update the database but idk what I'm missing not being able to get it all to talk to each other
sync function main() {
await prisma.twitterHandle.create({
data: {
twitterHandle: '~~@jennjunod',~~
},
})
const alltwitterHandles = await prisma.twitterHandle.findMany({
})
console.dir(alltwitterHandles, { depth: null })
}
I HOPE this all makes senseAlex Duguay
10/24/2022, 8:01 PM