Querying same content, but 1 different paramater. Should I clone and maintain both or better way?

I have a single query currently for a page.

.input(
z.object({
pokemon_id: z.number(),
form_id: z.number(),
costume_id: z.number(),
}),
).query(async ({ input, ctx }) => {
const pokemonDetails = await ctx.db
.select({
pokemon_id: pokemon.pokemon_id,
pokemon_english_name: pokemon.pokemon_english_name,
<-- removed for space -->
})
.from(pokemon)
.where(
and(
eq(pokemon.pokemon_id, input.pokemon_id),
eq(pokemon.form, input.form_id),
eq(pokemon.costume, input.costume_id),
),
);

.input(
z.object({
pokemon_id: z.number(),
form_id: z.number(),
costume_id: z.number(),
}),
).query(async ({ input, ctx }) => {
const pokemonDetails = await ctx.db
.select({
pokemon_id: pokemon.pokemon_id,
pokemon_english_name: pokemon.pokemon_english_name,
<-- removed for space -->
})
.from(pokemon)
.where(
and(
eq(pokemon.pokemon_id, input.pokemon_id),
eq(pokemon.form, input.form_id),
eq(pokemon.costume, input.costume_id),
),
);
Now on a nested page, I want to use id to grab exactly the same results and do the mutations etc. My question is, is there a way I can use this one query for both? Is there a better option on how to do this setup?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server