Hello, how can I import a (query)function from ano...
# orm-help
t
Hello, how can I import a (query)function from another file into my seed.ts? The create function for an (food) object in seed.ts is the same as for normal creation in my API route so I would like to import it from my routes/foods.ts into my seed.ts. The simplified functions looks like this (it actually has about 20 lines):
Copy code
export const createFood = async (food: CreateFood) => {
  const createdFood = await prisma.food.create({
    data: food,
  })
  return createdFood
}
I imported it into my seed.ts with:
import { createFood } from './../api/routes/foods'
And called it like this:
Copy code
async function main() {
  await createFood(food)
}
However if I run the seed command it never completes and always tells me Running ts-node "prisma/seed.ts" ... I think there might be an issue with different prisma clients?
r
@Tom 👋 Yes most probably that’s the issue and the
prisma
instance in used in
createFood
is not being disconnected which is why the script never ends.
You can either call
prisma.$disconnect()
explicitly or create a function in your seed file.
t
I solved it by importing the prisma instance from the backend, too.
💯 1