edarcode
edarcode
Explore posts from servers
DTDrizzle Team
Created by edarcode on 8/17/2024 in #help
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;
};
10 replies
DTDrizzle Team
Created by edarcode on 8/16/2024 in #help
seed
No description
14 replies
PPrisma
Created by edarcode on 8/13/2024 in #help-and-questions
self-relation
Greetings! Could someone help me? I haven't been able to understand this. I'm checking the followers and following of a user and everything appears correct in my db, but then when I check it the result is reversed. Any idea why? That 1 should appear in following and not in followers.
30 replies
PPrisma
Created by edarcode on 8/6/2024 in #help-and-questions
self-relation
No description
2 replies
PPrisma
Created by edarcode on 6/13/2024 in #help-and-questions
reset db and migrate changes
greetings! I am starting with Prisma ORM, I am having difficulty restarting the database and migrating changes made in my project in an automated way. Could someone show me an example? I speak Spanish, but I use Google translate
2 replies