Internal server error: Error connecting to database: fetch failed

I'm trying to send the following query to my db but it eventually times out, throwing an error:

  const currentCity = await db.query.city.findFirst({
    where: and(
      eq(city.slug, citySlug),
      eq(city.stateName, stateSlugToStateName(stateSlug))
    ),
  });

  const facilities = await db.query.facility.findMany({
    where: and(
      eq(facility.showOnListPage, true),
      gte(facility.addressLat, currentCity.lat - LAT_RADIUS),
      lte(facility.addressLat, currentCity.lat + LAT_RADIUS),
      gte(facility.addressLng, currentCity.lng - LNG_RADIUS),
      lte(facility.addressLng, currentCity.lng + LNG_RADIUS),
      whereLevelOfCare(levelOfCare)
    ),
    limit: 20,
    orderBy: desc(facility.internalRating),
    with: {
      city: true,
      apartments: true,
      images: true,
      amenityToFacility: {
        with: {
            amenity: true
        }
      }
    },
  });


If I comment out the facilities query, the city query returns just fine, so I don't think there's anything wrong with my env setup or connector code. This is also the same query that I previously sent via prisma (or at least, my best attempt at recreating it), and it worked there, so I don't think the query is failing due to its intrinsic size.

Any ideas as to how to resolve this issue?
Was this page helpful?