Oleg Yarin
11/14/2021, 5:10 PMprisma.create
:
await this.prisma.statement.create({
data: {
contextId,
content: statementData.content,
},
});
It seems that prisma sends two SQL queries to database:
prisma:query INSERT INTO "public"."Statement" ("content","contextId","createdAt") VALUES ($1,$2,$3) RETURNING "public"."Statement"."id"
prisma:query SELECT "public"."Statement"."id", "public"."Statement"."content", "public"."Statement"."contextId", "public"."Statement"."createdAt" FROM "public"."Statement" WHERE "public"."Statement"."id" = $1 LIMIT $2 OFFSET $3
Is there a way to exclude sending a second query in this scenario?Oleg Yarin
11/14/2021, 5:14 PM.update
function of the client API
I am trying to update a record with provided id:
const updateStatement = await this.prisma.statement.update({
where: { id },
data: {
content: statementData.content,
},
});
Prisma client in such a case sends three sql queries to databse
prisma:query SELECT "public"."Statement"."id" FROM "public"."Statement" WHERE "public"."Statement"."id" = $1
prisma:query UPDATE "public"."Statement" SET "content" = $1 WHERE "public"."Statement"."id" IN ($2)
prisma:query SELECT "public"."Statement"."id", "public"."Statement"."content", "public"."Statement"."contextId", "public"."Statement"."createdAt" FROM "public"."Statement" WHERE "public"."Statement"."id" = $1 LIMIT $2 OFFSET $3
I see it correctly, the first query does not make sense. Could you confirm that this is the case?Jin
11/14/2021, 5:57 PMJames Pickard
11/15/2021, 12:20 PMnpx prisma db pull
it is using a plural for a one-to-many foreign key (e.g. I have a key called control_id
but it generates a field on the model called controls
- not control
) is that a bug?Jordansz
11/15/2021, 12:25 PMArgument id: Got invalid value 'ckvxz34bl0000074mhkz1y27g' on prisma.findManyMembership. Provided String, expected IntFilter or Int:
errorJordansz
11/15/2021, 12:25 PMJordansz
11/15/2021, 12:28 PMRiccardo Nigrelli
11/15/2021, 2:09 PMupdate
error when the entity with a specific id
doesn't exist. For example, I wrote this function to update one entry of a specific table:
updateEntity(_: Subscribed, id: number, data: Prisma.UtilityTypeUpdateInput): Promise<DAORes<UtilityType>>;
updateEntity(_: Subscribed, id: number, ref: Number): Promise<DAORes<UtilityType>>;
async updateEntity(_: Subscribed, id: any, param: any): Promise<DAORes<UtilityType>> {
try {
if (typeof param !== 'object') throw new Error('Param type not supported');
const entity = await this.prisma.utilityType.update({ where: { id: id }, data: param });
return { status: 'UPDATED', entity };
}
catch (err) {
process.env.DEBUG === '1' && console.log(`[ERR]: ${err}`);
return { status: 'INTERNAL_ERROR', messageKey: 'ErrorUpdateResource' };
}
}
If id
doesn't exist in the table the error is correctly catched. Is there a way to had more granularity to the error since the err
hasn't any code error?Kristofer Pervin
11/15/2021, 3:51 PMldlework
11/15/2021, 5:50 PMuser
11/15/2021, 6:10 PMLars Ivar Igesund
11/15/2021, 6:13 PMJosef Henryson
11/15/2021, 8:02 PMJoonatan
11/15/2021, 9:01 PMAnderson da Silva
11/15/2021, 9:12 PMAhmet
11/16/2021, 12:56 AMAntoin Campbell
11/16/2021, 2:08 AMmodel User {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
firstName String?
lastName String?
email String? @unique
profile Profile?
role UserRole @default(USER)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([id, email])
}
model Profile {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
user User @relation(fields: [userId], references: [id])
userId String @db.Uuid
displayName String? @unique
biography String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
im trying to access user.profile
and it is telling me that the property profile does not exist on the model user. im having trouble understanding why this isnt possible or the right way to do thisAntoin Campbell
11/16/2021, 2:12 AMuser['profile']
notation? I just want to double checkAwey
11/16/2021, 6:47 AMmodel Follows {
createdAt DateTime @default(now())
follower User @relation("follower", fields: [followerId], references: [id])
followerId Int
following User @relation("following", fields: [followingId], references: [id])
followingId Int
@@id([followerId, followingId])
}
I want make sure followerId and followingId can never be the same.febreeze
11/16/2021, 9:52 AMuser
11/16/2021, 10:45 AMMichael Anderjaska
11/16/2021, 11:33 AMuser
11/16/2021, 12:06 PMOctavio Augusto Barbosa
11/16/2021, 2:29 PMJonas
11/16/2021, 3:36 PMJoshua Reilly
11/16/2021, 3:40 PMprisma db pull
but does not work with prisma migrate dev
. Is this a bug?
Error: P1012: error: Error validating: This line is not a valid definition within a datasource.
--> schema.prisma:4
|
3 | provider = "sqlserver"
4 | url = "<sqlserver://goblin>\dev:1434;database=stats;integratedSecurity=true;trustServerCertificate=true;"
5 | }
|
Garrick Chippendale
11/16/2021, 4:11 PMOrder by relevance in full text search (PostgreSQL)
, and maybe im misunderstanding it, but im having an issue:
const cards = await prisma.card.findMany({
include: {
character: true,
creator: true
},
where: {
character: {
name: {
contains: value,
mode: 'insensitive'
}
},
user_id: member.user.id
},
take: 10,
// Here <-------------
orderBy: {
_relevance: {
fields: [{ character: ['name'] }],
search: value,
sort: 'desc'
}
}
});
this definitely fails, because i just made up/guessed the syntax for fields
, but the only 2 fields i can input are the unique fields, which are just the IDs that arent useful at all for search/ordering/etc. it only lets me put user_id
and creator_id
as the fields, but i would expect i can sort by the character.name
which is the important string that the user is searching for.user
11/16/2021, 4:19 PMLuis Haroldo Castro Cabrera
11/16/2021, 5:13 PM