Count issues with libsql (Turso)

const locations = await db.query.locationsTable.findMany({
    extras(fields, { sql }) {
      return {
        groupsCount: sql<number>`
        (SELECT COUNT(*) 
         FROM ${groupsTable} 
         WHERE ${fields.id} = ${groupsTable.locationId}
        )`.as("groups_count"),
        eventsCount: sql<number>`
         (SELECT COUNT(*) 
          FROM ${eventsTable} 
          WHERE ${fields.id} = ${eventsTable.locationId}
         )`.as("events_count
"),
      };
    },
  });


Always getting 0 for groupsCount and eventsCount.
and $count is always throwing error.
Anyone have idea how can i add couts for groups and events ??
Was this page helpful?