© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•15mo ago•
1 reply
Michael Francis

Query API Returned Structure

Is there a way to change the structure of the result of the query API.

Here's an example showing what it currently does, and what I'd like to do.

  const result = await db.query.tableGame.findFirst({
    with: {
      gameCategories: true,
    },
  });
  console.log();

  // The current result type is
  const result: {
    userId: string | null;
    createdAt: number;
    updatedAt: number;
    deletedAt: number | null;
    gameId: string;
    title: string;
    publisher: string;
    numberOfPlayers: number;
    playtime: number;
    coverImageUrl: string | null;
    gameCategories: {
        createdAt: number;
        updatedAt: number;
        deletedAt: number | null;
        gameId: string | null;
        categoryId: string | null;
        gameCategoryId: string;
    }[];
} | undefined

  // is there an easy way to make it do this
  const result: {
    game: {
      userId: string | null;
      createdAt: number;
      updatedAt: number;
      deletedAt: number | null;
      gameId: string;
      title: string;
      publisher: string;
      numberOfPlayers: number;
      playtime: number;
      coverImageUrl: string | null;
    }
    gameCategories: {
        createdAt: number;
        updatedAt: number;
        deletedAt: number | null;
        gameId: string | null;
        categoryId: string | null;
        gameCategoryId: string;
    }[];
} | undefined
  const result = await db.query.tableGame.findFirst({
    with: {
      gameCategories: true,
    },
  });
  console.log();

  // The current result type is
  const result: {
    userId: string | null;
    createdAt: number;
    updatedAt: number;
    deletedAt: number | null;
    gameId: string;
    title: string;
    publisher: string;
    numberOfPlayers: number;
    playtime: number;
    coverImageUrl: string | null;
    gameCategories: {
        createdAt: number;
        updatedAt: number;
        deletedAt: number | null;
        gameId: string | null;
        categoryId: string | null;
        gameCategoryId: string;
    }[];
} | undefined

  // is there an easy way to make it do this
  const result: {
    game: {
      userId: string | null;
      createdAt: number;
      updatedAt: number;
      deletedAt: number | null;
      gameId: string;
      title: string;
      publisher: string;
      numberOfPlayers: number;
      playtime: number;
      coverImageUrl: string | null;
    }
    gameCategories: {
        createdAt: number;
        updatedAt: number;
        deletedAt: number | null;
        gameId: string | null;
        categoryId: string | null;
        gameCategoryId: string;
    }[];
} | undefined
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

Returned type inference when using tanstack query
Drizzle TeamDTDrizzle Team / help
2y ago
Aggregation with Query API
Drizzle TeamDTDrizzle Team / help
3y ago
Is this query possible using the Query API?
Drizzle TeamDTDrizzle Team / help
15mo ago
Joins with the Query API
Drizzle TeamDTDrizzle Team / help
2y ago