sal.tor
sal.tor
TTCTheo's Typesafe Cult
Created by Simvolick on 3/4/2023 in #questions
tRPC and querying data from external api
😁 glad to be of help!
45 replies
TTCTheo's Typesafe Cult
Created by Simvolick on 3/4/2023 in #questions
tRPC and querying data from external api
@Simvolick any luck with this?
45 replies
TTCTheo's Typesafe Cult
Created by Simvolick on 3/4/2023 in #questions
tRPC and querying data from external api
Because mutate doesn’t return your value, it uses callbacks like onSettled
45 replies
TTCTheo's Typesafe Cult
Created by Simvolick on 3/4/2023 in #questions
tRPC and querying data from external api
Is how i would do it
45 replies
TTCTheo's Typesafe Cult
Created by Simvolick on 3/4/2023 in #questions
tRPC and querying data from external api
const { mutate } = trpc.your.thing.useMutation()

function handleClick(e:any) {
e.preventDefault();
mutate({ text: message }, {
onSettled(data, error) {
if (error) return // handle this
if (data) setGeneratedText(data)
}
})
}
const { mutate } = trpc.your.thing.useMutation()

function handleClick(e:any) {
e.preventDefault();
mutate({ text: message }, {
onSettled(data, error) {
if (error) return // handle this
if (data) setGeneratedText(data)
}
})
}
45 replies
TTCTheo's Typesafe Cult
Created by Simvolick on 3/4/2023 in #questions
tRPC and querying data from external api
Like Vincent said, use “useMutation()” at the beginning of the component like you do with useState. You’ll deconstruct the mutate function and then use it in your event handler like this
45 replies
TTCTheo's Typesafe Cult
Created by Simvolick on 3/7/2023 in #questions
Any resources to learn the tRPC better? Hopefully with guides and examples?
I can try and take a look to help in a few hours
18 replies
TTCTheo's Typesafe Cult
Created by Simvolick on 3/7/2023 in #questions
Any resources to learn the tRPC better? Hopefully with guides and examples?
I commented on yhe first link but i dont have access to ghat second one
18 replies
TTCTheo's Typesafe Cult
Created by Simvolick on 3/4/2023 in #questions
tRPC and querying data from external api
Ill take a look in a few hours
45 replies
TTCTheo's Typesafe Cult
Created by Simvolick on 3/7/2023 in #questions
Any resources to learn the tRPC better? Hopefully with guides and examples?
@Simvolick do you have the sense that in the api changes something changed with context? And is there anything specifically you’re having trouble with?
18 replies
TTCTheo's Typesafe Cult
Created by janusqa on 3/6/2023 in #questions
Error: Cannot find module '@tailwindcss/typography'
Did you fix this yet?
6 replies
TTCTheo's Typesafe Cult
Created by janusqa on 3/6/2023 in #questions
Error: Cannot find module '@tailwindcss/typography'
Can you show your package json? I assume you’ve installed tailwindcss but have you also installed the specific package “@tailwindcss/typography”?
6 replies
TTCTheo's Typesafe Cult
Created by sal.tor on 3/5/2023 in #questions
Prisma: best way to structure these D&D schemas?
Yeah that’s an interesting historical thread, I’m going to dig into it on desktop tomorrow. I think for now my idea might work with your earlier links
8 replies
TTCTheo's Typesafe Cult
Created by sal.tor on 3/5/2023 in #questions
Prisma: best way to structure these D&D schemas?
Oh shoot yeah that’s a good name for it, Union type
8 replies
TTCTheo's Typesafe Cult
Created by sal.tor on 3/5/2023 in #questions
Prisma: best way to structure these D&D schemas?
To add to that im expecting ill be making a monster model that is associated only with battles
8 replies
TTCTheo's Typesafe Cult
Created by sal.tor on 3/5/2023 in #questions
Prisma: best way to structure these D&D schemas?
Hehe
8 replies
TTCTheo's Typesafe Cult
Created by sal.tor on 3/5/2023 in #questions
Prisma: best way to structure these D&D schemas?
Yeah, i dont know necessarily whether that’s a 1:1 to “conditional join” since i know a tiny bit of sql but that sounds right
8 replies
TTCTheo's Typesafe Cult
Created by sal.tor on 3/5/2023 in #questions
Prisma: best way to structure these D&D schemas?
cc @Strike here's the additional context and schemas I mentioned I'd add to this thread
8 replies
TTCTheo's Typesafe Cult
Created by sal.tor on 3/5/2023 in #questions
Prisma: best way to structure these D&D schemas?
To get all the data I want up front for the frontend, aka the battle order and each entity's information, I'd ideally be able to do a prisma query like this
prisma.battleparticipant.findMany({
where: { id: battle_id },
include: { entity: true }
})
prisma.battleparticipant.findMany({
where: { id: battle_id },
include: { entity: true }
})
But because entity isn’t an actual model but is instead one of multiple possible models, this wouldn't work (as far as I see right now) The alternative I can think of is to get all the BattleParticipants and then iterate over them and based on the entity type I can query the appropriate table and ultimately combine them
const participants = await prisma.battleparticipants.findMany({ where: { id: battle_id } })
const entityData = []
participants.forEach(participant => {
if (participant.entityType === 'player') {
entityData.push(prisma.player.findUnique({ where: { id: participant.entityId } })
} else if (participant.entityType === 'npc') {
entityData.push(prisma.npc.findUnique({ where: { id: participant.entityId } })
}
})
await Promise.all(entityData)
return participants.map((p, index) => ({ ...p, entity: entityData[index] }))
const participants = await prisma.battleparticipants.findMany({ where: { id: battle_id } })
const entityData = []
participants.forEach(participant => {
if (participant.entityType === 'player') {
entityData.push(prisma.player.findUnique({ where: { id: participant.entityId } })
} else if (participant.entityType === 'npc') {
entityData.push(prisma.npc.findUnique({ where: { id: participant.entityId } })
}
})
await Promise.all(entityData)
return participants.map((p, index) => ({ ...p, entity: entityData[index] }))
So, does this approach to make a BattleParticipant model make sense? Or is there a better way to get the data all at once?
8 replies