Phil Bookst
10/06/2021, 10:15 AMmodel Hashtag {
id String? @unique
name String @id
thumbnail String?
post_count Int?
images Image[]
imageHashtags ImageHashtags[]
@@map("hashtag")
}
model Image {
id String @id
thumbnail String
shortcode String @unique
like_count Int
comment_count Int
caption String? @db.Text
hashtag Hashtag? @relation(fields: [hashtagName], references: [name])
hashtagName String?
imageHashtags ImageHashtags[]
@@index([hashtagName])
@@map("image")
}
// Explicit m-n relation good fit for this use case?
model ImageHashtags {
imageId String
image Image @relation(fields: [imageId], references: [id])
name String
hashtag Hashtag @relation(fields: [name], references: [name])
count Int
@@id([imageId, name])
}
i'm using the ImageHashtags table to keep a count of how many hashtags were used in an image caption to later aggregate on the hashtag name to find out how often a profile uses a specific hashtag
this is working fine but it pollutes my database a lot... right now I have about 10k image rows and 100k rows in the ImageHashtags.
is there a way to do this more effectively to reduce row writes?sagar lama
10/06/2021, 11:15 AMError: Unable to require(`/app/node_modules/@prisma/engines/libquery_engine-linux-musl.so.node`)
Error loading shared library libssl.so.3: No such file or directory (needed by /app/node_modules/@prisma/engines/libquery_engine-linux-musl.so.node)
ERROR: 1
I ran the command using docker-compose run api npx prisma migrate dev
My Dockerfile looks like this.
FROM node:14-alpine as development
RUN apk add --no-cache git gcc g++ python
WORKDIR /app
COPY ./ ./
RUN npm ci --ignore-scripts --prefer-offline --silent --no-progress --no-audit
What am I missing?sagar lama
10/06/2021, 11:15 AMNathaniel Babalola
10/06/2021, 11:31 AMAmit
10/06/2021, 12:46 PMJson?
field (optional JSON), I can't use undefined
because it then just treats it like there's no key, and I can't use null
because then Prisma is angry with me.
Can someone please help me update an object in such way?
It's not a key within the JSON, but literally I want to update a previously updated JSON (say {"a": "b"}
) to NULLEndyKaufman
10/06/2021, 1:11 PMEndyKaufman
10/06/2021, 1:12 PMDaniel Uhm
10/06/2021, 4:21 PMimport { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
prisma.$use(async (params, next) => {
const bypassSoftDeleted: string[] = [];
if (params.model && !bypassSoftDeleted.includes(params.model)) {
if (!['create', 'update', 'upsert', 'delete'].includes(params.action)) {
if (!params.args.where) params.args.where = {};
if (!params.args.where['deletedAt']) {
params.args.where['deletedAt'] = null;
}
}
if (['delete', 'deleteMany'].includes(params.action)) {
if (params.action === 'delete') params.action = 'update';
if (params.action === 'deleteMany') params.action = 'updateMany';
if (!params.args.data) params.args.data = {};
params.args.data['deletedAt'] = new Date();
}
}
return next(params);
});
export { prisma };
The middleware above is a soft delete. Thanks for reading.Andrew Ross
10/06/2021, 7:49 PMAndrew Ross
10/06/2021, 7:49 PMBrendo Souza
10/06/2021, 11:24 PMJohannes Bolten
10/06/2021, 11:41 PMYeonHoPark
10/07/2021, 1:47 AMconst _user_ = _await prisma.user.findUnique_({
_where_:
{
_id_:
1,
},
})
_const userJson_ = _user.json as UserJson_
type UserJson = {
name: string
age: number
}
Jack Chen
10/07/2021, 3:25 AMuser
10/07/2021, 12:21 PMhttps://www.youtube.com/watch?v=NaxQXClnYSE&list=PLn2e1F9Rfr6k6MwzS-p9FGK1NDBxxwLPk&index=18&pp=sAQB▾
https://www.youtube.com/watch?v=NaxQXClnYSE&list=PLn2e1F9Rfr6k6MwzS-p9FGK1NDBxxwLPk&index=16&pp=sAQB▾
Reuben Porter
10/07/2021, 1:03 PMprisma.$queryRaw
and using sql ORDER BY
. I am passing in the order by and direction values as parameters, however the query is not working
e.g.
ORDER BY ${orderBy} ${direction}
should become
ORDER BY name ASC
Don't suppose anyone has any ideas? Before I've used pg promise :raw
but not sure how to do this the 'prisma way'.
Apologies if anything isn't clear.Peter
10/07/2021, 2:44 PM""<postgresql://userName@PasswordWithEncodedSpecialCharacters@MyServer.postgres.database.azure.com:5432/DBName?schema=SomeSchema&connect_timeout=100>"
npx prisma migrate dev --name init
Fails with Error: P1001: Can't reach database server at..
Maybe to clarify, I basically opened everything up to the outside from within Azure, and using my local SQL Admin Tool to connect to it from the same PC works like a charme..Vladi Stevanovic
Yilmaz Ugurlu
10/07/2021, 3:34 PMBu when I do and runWhile you cannot configure these option in your Prisma schema, you can still configure them on the database-level directly.
migrate
I get:
Drift detected: Your database schema is not in sync with your migration history.
The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database.
It should be understood as the set of changes to get from the expected schema to the actual schema.
[*] Changed the `event` table
[+] Added index on columns (created_at, event_name)
[+] Added index on columns (created_at, event_name)
[+] Added index on columns (created_at, event_name)
So, what am I doing wrong here? Any idea?Julia Cassemiro
10/07/2021, 3:41 PMEvan McDaniel
10/07/2021, 4:06 PMschema.prisma
and Nexus schema.ts
files will become tedious for our team pretty quickly.
It seems that the Prisma Nexus plugin might help with this, but it looks to be in some sort of in-between state. I looked at TypeGraphQL as well but wasn’t sure if that actually would solve this specific issue. It looks like Pal.js might do solve this, though, so I wondered if that’s what folks are considering a best practice for this at the moment.
Also have heard others say that maintaining separation between database and gQL schemas is actually the best practice, though I’ve yet to come up against a use case in our app that makes this clear.
Open to all thoughts and ideas. Thanks!Kamran Tahir
10/07/2021, 6:24 PMKamran Tahir
10/07/2021, 6:25 PMKamran Tahir
10/07/2021, 6:25 PMJin
10/07/2021, 8:19 PMYashu Mittal
10/08/2021, 5:17 AMLOWER(db_column) LIKE LOWER(?)
it is easy to lowercase the right part, but how to lowercase the left part before matching the valueAdam Herbert
10/08/2021, 5:32 AMuser
10/08/2021, 6:54 AMhttps://www.youtube.com/watch?v=NaxQXClnYSE&list=PLn2e1F9Rfr6k6MwzS-p9FGK1NDBxxwLPk&index=18&pp=sAQB▾
user
10/08/2021, 12:31 PMPrince
10/08/2021, 12:40 PM