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
TtRPC
Created by Bean on 4/1/2024 in #❓-help
type safety with meta
No description
7 replies
PPrisma
Created by Bean on 3/28/2024 in #help-and-questions
StringFieldUpdateOperationsInput on @id
No description
1 replies
TTCTheo's Typesafe Cult
Created by Bean on 9/11/2023 in #questions
What kind of db/storage do I need?
I am trying to make an app but I am confuse by all the DB options and idk what is the best option for me. I am making a public bus tracking app for a city. There is a public API I am able to use to get the current location of all the buses in the city. So, I wanted scape that API every few seconds and store that data so I can track the performance of the buses over time and see when they are usually late/full/early, etc. the API returns the live GPS and the passenger count as well as some extra info. I ran the scraper for a couple days and it looks like the raw json (without cleaning it up for formatting it correctly) results in about 1gb/week. I can easily bring that down to 800mb/week. what do you think would be the best way to store, access this data? I am currently planning on using pocketbase but I don't know if thats the best option.
5 replies