Mr.Propre
Mr.Propre
Explore posts from servers
NNuxt
Created by Mr.Propre on 3/2/2024 in #❓・help
Nuxt UI Icons
Can please someone explain to me how to use Nuxt UI Icons ??? The documentation says : Use the name prop by following this pattern: i-{collection_name}-{icon_name}. But for some reason is doesn't work for me. This is what im attempting to do:
<ULink to="/">
<UIcon name="i-cib-facebook" />
</ULink>
<ULink to="/">
<UIcon name="i-cib-facebook" />
</ULink>
And this is the icon i want to use: https://icones.js.org/collection/cib?s=face
6 replies
DTDrizzle Team
Created by Mr.Propre on 11/30/2023 in #help
relation select query with where condition
I want to select all user's tasks where parent id is null. Can someone help me fix this query please:
const result = await db.query.usersTasks.findMany({
with: {
tasks: {
with: {
subtasks: true,
},
where: isNull(tasks.parentId),
},
},
where: eq(usersTasks.userId, id),
});
const result = await db.query.usersTasks.findMany({
with: {
tasks: {
with: {
subtasks: true,
},
where: isNull(tasks.parentId),
},
},
where: eq(usersTasks.userId, id),
});
these are the tables in question :
export const users = mysqlTable("users", {
userId: varchar("userId", { length: 256 }).primaryKey().notNull().unique(),
theme: mysqlEnum("theme", ["DARK", "LIGHT"]).default("DARK"),
createdAt: timestamp("created_at").default(sql`CURRENT_TIMESTAMP`),
updatedAt: timestamp("updated_at").default(sql`CURRENT_TIMESTAMP`),
});
export const usersTasks = mysqlTable(
"users_tasks",
{
id: int("id").primaryKey().autoincrement(),
userId: varchar("user_id", { length: 256 }).references(() => users.userId),
taskId: int("tas_id").references(() => tasks.id),
createdAt: timestamp("created_at").default(sql`CURRENT_TIMESTAMP`),
updatedAt: timestamp("updated_at").default(sql`CURRENT_TIMESTAMP`),
}
);
export const tasks = mysqlTable(
"tasks",
{
id: int("id").primaryKey().autoincrement(),
parentId: int("parent_id").references((): AnyMySqlColumn => tasks.id),
title: varchar("title", { length: 256 }).notNull(),
description: varchar("description", { length: 2000 }),
dueDate: datetime("due_date"),
createdAt: timestamp("created_at").default(sql`CURRENT_TIMESTAMP`),
updatedAt: timestamp("updated_at").default(sql`CURRENT_TIMESTAMP`),
},
(table) => ({
parentIdx: index("parent_idx").on(table.parentId)
})
);

export const usersRelations = relations(users, ({ many }) => ({
userTasks: many(usersTasks)
}));
export const tasksRelations = relations(tasks, ({ many, one }) => ({
userTasks: many(usersTasks),
subtasks: many(tasks, { relationName: "subtasks" }),
parent: one(tasks)
}));
export const users = mysqlTable("users", {
userId: varchar("userId", { length: 256 }).primaryKey().notNull().unique(),
theme: mysqlEnum("theme", ["DARK", "LIGHT"]).default("DARK"),
createdAt: timestamp("created_at").default(sql`CURRENT_TIMESTAMP`),
updatedAt: timestamp("updated_at").default(sql`CURRENT_TIMESTAMP`),
});
export const usersTasks = mysqlTable(
"users_tasks",
{
id: int("id").primaryKey().autoincrement(),
userId: varchar("user_id", { length: 256 }).references(() => users.userId),
taskId: int("tas_id").references(() => tasks.id),
createdAt: timestamp("created_at").default(sql`CURRENT_TIMESTAMP`),
updatedAt: timestamp("updated_at").default(sql`CURRENT_TIMESTAMP`),
}
);
export const tasks = mysqlTable(
"tasks",
{
id: int("id").primaryKey().autoincrement(),
parentId: int("parent_id").references((): AnyMySqlColumn => tasks.id),
title: varchar("title", { length: 256 }).notNull(),
description: varchar("description", { length: 2000 }),
dueDate: datetime("due_date"),
createdAt: timestamp("created_at").default(sql`CURRENT_TIMESTAMP`),
updatedAt: timestamp("updated_at").default(sql`CURRENT_TIMESTAMP`),
},
(table) => ({
parentIdx: index("parent_idx").on(table.parentId)
})
);

export const usersRelations = relations(users, ({ many }) => ({
userTasks: many(usersTasks)
}));
export const tasksRelations = relations(tasks, ({ many, one }) => ({
userTasks: many(usersTasks),
subtasks: many(tasks, { relationName: "subtasks" }),
parent: one(tasks)
}));
20 replies
DTDrizzle Team
Created by Mr.Propre on 11/23/2023 in #help
Drizzle error instance
Is there a Drizzle error type that i can use for my Fastify global error handler ?? What im looking for is maybe something like the prisma error type Prisma.PrismaClientKnownRequestError, And what i want is to identify the drizzle error so i can handle them properly. this is how my global error handler looks :
export default function globalErrorHandler(
this: any,
error: FastifyError,
_req: FastifyRequest,
rep: FastifyReply
) {
this.log.error(error);

let statusCode = 500;
let message = "Internal server error";

switch (true) {
case error instanceof HttpError:
statusCode = error.status;
message = error.message;
break;

case error instanceof Error:
statusCode = error.statusCode ?? statusCode;
message = error.message;
break;

default:
break;
}

rep.code(statusCode).send({ message: message, success: false });
}
export default function globalErrorHandler(
this: any,
error: FastifyError,
_req: FastifyRequest,
rep: FastifyReply
) {
this.log.error(error);

let statusCode = 500;
let message = "Internal server error";

switch (true) {
case error instanceof HttpError:
statusCode = error.status;
message = error.message;
break;

case error instanceof Error:
statusCode = error.statusCode ?? statusCode;
message = error.message;
break;

default:
break;
}

rep.code(statusCode).send({ message: message, success: false });
}
If there is a better way to handler db errors that i can use please tell me
5 replies