© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•12mo ago•
2 replies
harshmangalam

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
"),
      };
    },
  });
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 ??
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Vector types/querys - Turso/LibSQL Support
Drizzle TeamDTDrizzle Team / help
2y ago
Turso Schema Database migration with drizzle-orm/libsql/migrator
Drizzle TeamDTDrizzle Team / help
2y ago
Issues with NextJS + Turso + DrizzleORM + LuciaAuth
Drizzle TeamDTDrizzle Team / help
2y ago
Get issue trying to run libsql/turso example
Drizzle TeamDTDrizzle Team / help
3y ago