© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
9 replies
edarcode

query with

// schema
export const usersTable = sqliteTable("users", {
  id: text("id").primaryKey(),
  username: text("username"),
  // otros campos...
});

export const followsTable = sqliteTable(
  "follows",
  {
    followerId: text("follower_id").references(() => usersTable.id),
    followingId: text("following_id").references(() => usersTable.id),
    createdAt: text("created_at").default(sql`(CURRENT_TIMESTAMP)`),
  },
  (followsTable) => ({
    id: primaryKey([followsTable.followerId, followsTable.followingId]),
  })
);
// schema
export const usersTable = sqliteTable("users", {
  id: text("id").primaryKey(),
  username: text("username"),
  // otros campos...
});

export const followsTable = sqliteTable(
  "follows",
  {
    followerId: text("follower_id").references(() => usersTable.id),
    followingId: text("following_id").references(() => usersTable.id),
    createdAt: text("created_at").default(sql`(CURRENT_TIMESTAMP)`),
  },
  (followsTable) => ({
    id: primaryKey([followsTable.followerId, followsTable.followingId]),
  })
);

I'm trying to do this query, but "with" doesn't recommend anything, did I link my schema wrong?

import { db } from "../../../db/db";
import { EdarErr } from "../../../error/EdarErr";
import { Uuid } from "../../../types";

export const getAccountService = async (id: Uuid) => {
  const account = await db.query.usersTable.findFirst({
    where: (user, { eq }) => eq(user.id, id),
    with: { ?: true },
  });

  if (!account) throw new EdarErr(404, "Account not found");

  return account;
};
import { db } from "../../../db/db";
import { EdarErr } from "../../../error/EdarErr";
import { Uuid } from "../../../types";

export const getAccountService = async (id: Uuid) => {
  const account = await db.query.usersTable.findFirst({
    where: (user, { eq }) => eq(user.id, id),
    with: { ?: true },
  });

  if (!account) throw new EdarErr(404, "Account not found");

  return account;
};
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

count() within query.findMany.with
Drizzle TeamDTDrizzle Team / help
14mo ago
trying to use $count withing query relational api
Drizzle TeamDTDrizzle Team / help
13mo ago
Issues with query
Drizzle TeamDTDrizzle Team / help
9mo ago
Help with query
Drizzle TeamDTDrizzle Team / help
2y ago