Henrique Aurelio
05/03/2022, 7:06 PMZak
05/03/2022, 7:51 PMJunior-Web-Dev
05/03/2022, 8:13 PMSELECT *
FROM "token"
INNER JOIN "user" u on u.user_id = token.user_id
WHERE u.email = '<mailto:abc@abc.com|abc@abc.com>'
Junior-Web-Dev
05/03/2022, 8:17 PMJunior-Web-Dev
05/03/2022, 8:23 PMawait prisma.token.update({
data: {
user: {
connectOrCreate: {
where: {
email: user.email
},
create: {
token: user.token
}
}
}
},
include: {
user: true
}
})
The logic is update "token" column where "user_id" is fk to "user" table...find "token" based off "email" in "user" table... hope it makes senseJunior-Web-Dev
05/03/2022, 9:07 PMawait prisma.token.upsert({
where: {
'user_id': dbUser.user_id
},
data: {
'token': refreshToken
},
create: {
'user_id': dbUser.user_id,
'token': refreshToken
}
});
Junior-Web-Dev
05/03/2022, 9:09 PMJunior-Web-Dev
05/03/2022, 9:13 PMJunior-Web-Dev
05/03/2022, 9:18 PMLuke Morris
05/03/2022, 11:47 PMSELECT *
, and trying to map column values into required fields in the resulting JS object. Any advice on what to do here? Is there a way for me to exclude a field from my prisma client without modifying the underlying database schema?Jason Kleinberg
05/04/2022, 12:56 AM@db.Decimal(XX, 5)
? For some reason when I set my data to 5 decimal places, the values come out like 12.000000000000002
. Not only is it adding a float rounding error, they have too many decimal places. Setting it to 2,3,4,and 6 work fine. I haven’t checked above that point.Slackbot
05/04/2022, 8:38 AMAlfred Noland
05/04/2022, 9:06 AMDominik Jašek
05/04/2022, 10:57 AMschema.prisma
? This plugin really sucks… https://plugins.jetbrains.com/plugin/14240-prismaalexwasik
05/04/2022, 11:53 AMmodel Player {
id String @id
username String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
losses Match[] @relation("Losses")
resigned Match[] @relation("Resigned")
wins Match[] @relation("Wins")
moves Move[]
matches PlayerMatch[]
rolls Roll[]
lastLogin DateTime?
}
Luke Morris
05/04/2022, 3:39 PMInvalid `prisma.user.findUnique()` invocation:
The column `User.removedField` does not exist in the current database.
Hugo Vallejo
05/04/2022, 4:16 PMBerian Chaiwa
05/04/2022, 5:00 PMcontains
fails to match if filter is the first word of text? E.g., Say description="Chaiwa is a good guy"
, sending filter: "guy"
matches this record but sending filter: "chai"
fails. See implementation of the where clause for the query below:
const where = args.filter
? {
OR: [
{
description: { contains: args.filter },
url: { contains: args.filter },
},
],
}
: {};
Omar
05/04/2022, 7:15 PMzod-prisma
but so far it keeps getting stuck at the generation step.
Has anybody here experienced this issue?Yaakov
05/04/2022, 8:39 PMstring
into rust type `String``
at Object.transaction (/usr/src/app/node_modules/@prisma/client/runtime/index.js:41312:64)
at async Proxy._transactionWithCallback (/usr/src/app/node_modules/@prisma/client/runtime/index.js:46414:21)
model Person {
id Int @id @default(autoincrement())
name String
}
<http://router.post|router.post>('/person', (req, res, next) => {
prisma.$transaction(async (prisma) => {
const person = await prisma.person.create({
data: {
name: 'A new role',
},
});
// Do something else
return person;
}).then(person => res.status(201).json(person))
.catch(next);
});
david
05/04/2022, 11:40 PMmodel foo {
id String @id
bar Int[]
}
when I have: bar = [0, 0]
and call
prisma.foo.create({
data: {
bar
},
the array is saved in the database, but when I try to set one of the values to null bar = [null, 0]
I get a vague error failed: {"clientVersion":"3.12.0"}
I tried turning on extra debug logging, but I’m not getting any useful info. I can also directly update the row directly in postgres without any issues ( … set bar = ‘{null,0}’) Is it possible to set null values in an integer array through prisma? I appreciate any help you can provide.Jawad Sefiani
05/05/2022, 12:28 AMprisma migrate dev
is overwriting a custom migration that I wrote to alter one of my tables, this is the custom SQL script (I first created an empty migration using --create-only):
-- AlterTable
ALTER TABLE "menu-item-translations"
DROP CONSTRAINT "menu-item-translations_menuItemId_fkey",
ADD CONSTRAINT "menu-item-translations_menuItemId_fkey"
FOREIGN KEY ("menuItemId") REFERENCES "menu-items"("id") ON DELETE CASCADE ON UPDATE CASCADE;
After that I ran prisma migrate dev
but it creates another migration (which i don't want because it removes the cascade behavior, idk why Prisma is doing this???):
-- DropForeignKey
ALTER TABLE "menu-item-translations" DROP CONSTRAINT "menu-item-translations_menuItemId_fkey";
-- AddForeignKey
ALTER TABLE "menu-item-translations" ADD CONSTRAINT "menu-item-translations_menuItemId_fkey" FOREIGN KEY ("menuItemId") REFERENCES "menu-items"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Yerzhan
05/05/2022, 1:01 AMmigrations
folder + _prisma_migrations
table. it’s kind of ok for working on migrations for 1 person. but, did anyone face any problems with creating a few migrations in 10 PRs? which PR’s migration will go first when we merge? how do you handle the migration history in that case?
b. how to make sure that version control work as it expected? for example when 5 engineers works on the same table and created a few PRs that will somehow affect the same table?
2. how to rollback?
a. how do we rollback the latest local migration?
b. how do we rollback to the specific migration?
3. how to catch migration errors?
a. what happened if some migration fails? how do we know and fix it?
thanks!Devan Benz
05/05/2022, 1:37 AMDevan Benz
05/05/2022, 1:46 AMschema.prisma
file. So far it seems relatively straight forward but I have one field that is using a Record utility type in typescript. It’s type is Record<string, string | number | boolean | null | undefined>
is there a way to translate this into prisma’s schema file?Codingbutter llc
05/05/2022, 2:59 AMJawad Sefiani
05/05/2022, 12:32 PMJonathan
05/05/2022, 1:18 PM// Intantiation class in a /src/utils/makeTestPrisma.ts
export const makeTestPrisma = () => {
if (process.env.NODE_ENV === 'test') {
const prisma = global.testPrisma || new PrismaClient({
datasources: { postgresql: { url: 'OUR_URL' } },
});
global.testPrisma = prisma;
return prisma;
}
throw new Error('Not possible; only works in Test environment!');
}
// In a test file, /src/Users/User.test.ts
const prisma = makeTestPrisma();
test(async () => {
const res = await services.doSomeStuffInDb(prisma);
expect(res.users).toEqual(2);
});
Omar
05/05/2022, 3:46 PMMathie
05/05/2022, 4:39 PMmodel Response {
id Int @id @default(autoincrement())
survey Survey @relation(fields: [surveyId], references: [id])
surveyId Int
user User @relation(fields: [userId], references: [id])
userId Int
sendAt DateTime @default(now())
json Json
}
How to use findUnique on the field user ?
I want to get the user with the ID 1