Bean
Bean
Explore posts from servers
PPrisma
Created by Bean on 7/12/2024 in #help-and-questions
create many skip existing
I want to createmany rows in a table, but if that row already exists (excluing the ID row), then skip that row. afaik, the skipDuplicates key will skip duplicates within the set of new rows you are adding, but it does not check the existing rows eg:
| id | col1 | col2 |
| 0 | aaa | bbb |
| 1 | ccc | ddd |
| 2 | eee | fff |
| id | col1 | col2 |
| 0 | aaa | bbb |
| 1 | ccc | ddd |
| 2 | eee | fff |
if I do createMany with skipDuplicates and add rows:
| col1 | col2 |
| aaa | bbb |
| ccc | ddd |
| eee | fff |
| col1 | col2 |
| aaa | bbb |
| ccc | ddd |
| eee | fff |
this will result in duplicate rows but with different ID keys.
how can I avoid this issue? I want to be able to automatically skip any rows that already exist. currently the ID key is set to autoincrement(). What should I do?
13 replies
PPrisma
Created by Bean on 4/16/2024 in #help-and-questions
union type findMany
I want to be able to query in prisma using a variable which is a union type over mulitple model tables. so instead of
const model : 'user' | 'post' | ...;
const id : number = 1;

switch (model) {
case 'user': prisma.user.findMany({where : id})
case 'post': prisma.post.findMany({where : id})
}
const model : 'user' | 'post' | ...;
const id : number = 1;

switch (model) {
case 'user': prisma.user.findMany({where : id})
case 'post': prisma.post.findMany({where : id})
}
I want to be able to do:
const model : 'user' | 'post' | ...
prisma[model].findMany({where : id} as const)
const model : 'user' | 'post' | ...
prisma[model].findMany({where : id} as const)
Since I have a really large schema and I do not want to repeat so many lines. but, even though each model/schema table has the id field as the same type and they all have this same key, TS is complaining that the signatures of each of the findMany functions are different for each table so I cannot do this. . I even tried using as const in case there was a difference there, but that did not help either. I am not sure how I can do this to make my code cleaner and easier to maintain. Here is an example in a codesandbox: https://codesandbox.io/p/devbox/dark-night-vsqs73
14 replies
PPrisma
Created by Bean on 4/15/2024 in #help-and-questions
will prisma support zod validations natively
I know there are plugins, but they all seem to be out of date and have issues with them not being always correct. I really wish this was natively integrated given how important this is to have. it just needs more cod gen in the generate function
1 replies
PPrisma
Created by Bean on 3/28/2024 in #help-and-questions
StringFieldUpdateOperationsInput on @id
No description
1 replies