jorge
jorge
Explore posts from servers
DTDrizzle Team
Created by jorge on 8/11/2024 in #help
drizzle-zod createInsertSchema gives optional types
I have the following table:
export const Recipe = pgTable("recipe", {
id: uuid("id").notNull().primaryKey().defaultRandom(),
title: varchar("title", { length: 256 }).notNull(),
description: text("description").notNull(),
mainImage: varchar("main_image", { length: 512 }),
ingredientNames: varchar("ingredient_names", { length: 255 }).array().notNull(), // Array of ingredient names
ingredientQuantities: real("ingredient_quantities").array().notNull(), // Array of ingredient quantities
ingredientUnits: varchar("ingredient_units", { length: 20 }).array().notNull(), // Array of ingredient units
stepDescriptions: text("step_descriptions").array().notNull(), // Array of step descriptions
stepImages: varchar("step_images", { length: 512 }).array().notNull(), // Array of step images
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at", {
mode: "date",
withTimezone: true,
}).$onUpdateFn(() => sql`now()`),
postedBy: uuid("posted_by").references(() => User.id, { onDelete: "cascade" }),
});
export const Recipe = pgTable("recipe", {
id: uuid("id").notNull().primaryKey().defaultRandom(),
title: varchar("title", { length: 256 }).notNull(),
description: text("description").notNull(),
mainImage: varchar("main_image", { length: 512 }),
ingredientNames: varchar("ingredient_names", { length: 255 }).array().notNull(), // Array of ingredient names
ingredientQuantities: real("ingredient_quantities").array().notNull(), // Array of ingredient quantities
ingredientUnits: varchar("ingredient_units", { length: 20 }).array().notNull(), // Array of ingredient units
stepDescriptions: text("step_descriptions").array().notNull(), // Array of step descriptions
stepImages: varchar("step_images", { length: 512 }).array().notNull(), // Array of step images
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at", {
mode: "date",
withTimezone: true,
}).$onUpdateFn(() => sql`now()`),
postedBy: uuid("posted_by").references(() => User.id, { onDelete: "cascade" }),
});
And I am using drizzle-zod to generate a Zod type from my schema:
export const CreateRecipeSchema = createInsertSchema(Recipe).omit({
id: true,
createdAt: true,
updatedAt: true,
});
export const CreateRecipeSchema = createInsertSchema(Recipe).omit({
id: true,
createdAt: true,
updatedAt: true,
});
However when I try to use the type within my tRPC procedure as such, I get a typescript error, which seems to be complaining that the properties within CreateRecipeSchema are optional:
create: publicProcedure
.input(CreateRecipeSchema)
.mutation(async ({ input, ctx }) => {
const newRecipe = await ctx.db.insert(Recipe).values(input);

return newRecipe;
}),
create: publicProcedure
.input(CreateRecipeSchema)
.mutation(async ({ input, ctx }) => {
const newRecipe = await ctx.db.insert(Recipe).values(input);

return newRecipe;
}),
I'm quite new to drizzle and zod, and from what I gather from documentation, I am using zod correctly, but I am not sure.
3 replies
MModular
Created by jorge on 3/4/2024 in #questions
Mojo implementation question regarding borrow checker
Hello, I am a student learning about Programming Language Theory and I have a question regarding Mojo's implementation of Borrow Checking. In Rust, borrow-checking is performed by statically analysing the types of variables at compile time. However in Mojo, there doesn't seem to be a type for references, and there also doesn't seem to be any syntax for dereferences. So my question is, how does Mojo perform its borrow checking? Does it automatically add a reference within the scope of the function? What if one needs to dereference? I understand that Mojo's compiler is currently closed source, but if anyone could point me towards any relevant papers, or give any detail on its implementation in contrast to Rust's implementation I would be very grateful. Thanks
5 replies
SSolidJS
Created by jorge on 7/25/2023 in #support
How to protect all routes other than sign-in
Hi there, I am making an app where I only want signed-in users to see the content, I want all routes to automatically redirect to the sign-up page if the user is not signed in. Ideally, I don't want to have to add the boilerplate to check if the user is signed up on every single page, I also don't want to have to create and maintain a massive list of all the protected routes (which is virtually every route in my app) when using middleware. What is an easy way of setting something like this up? Here is what I came up with, conditionally showing the route if the user has a session, though tbh it is a bit janky.
// root.tsx (omitting some lines)
export const useSession = () => {
return createServerData$(
async (_, { request }) => {
return await getSession(request, authOptions)
},
{ key: () => ["auth_user"] }
)
}

export default function Root() {
const session = useSession()
return (
<Html lang="en">
<Head>
</Head>
<Body>
<SessionProvider>
<Suspense>
<ErrorBoundary>
<Show when={session()}
fallback={
<div class="flex flex-col items-center justify-center gap-4">
<button
onClick={() => signIn("discord", { redirectTo: "/" })}
class="rounded-full bg-black/10 px-10 py-3 font-semibold"
>
Sign In
</button>
</div>
}
>
<div class="flex flex-row">
<Nav />
<Routes>
<FileRoutes />
</Routes>
</div>
</Show>
</ErrorBoundary>
</Suspense>
</SessionProvider>
<Scripts />
</Body>
</Html>
);
}
// root.tsx (omitting some lines)
export const useSession = () => {
return createServerData$(
async (_, { request }) => {
return await getSession(request, authOptions)
},
{ key: () => ["auth_user"] }
)
}

export default function Root() {
const session = useSession()
return (
<Html lang="en">
<Head>
</Head>
<Body>
<SessionProvider>
<Suspense>
<ErrorBoundary>
<Show when={session()}
fallback={
<div class="flex flex-col items-center justify-center gap-4">
<button
onClick={() => signIn("discord", { redirectTo: "/" })}
class="rounded-full bg-black/10 px-10 py-3 font-semibold"
>
Sign In
</button>
</div>
}
>
<div class="flex flex-row">
<Nav />
<Routes>
<FileRoutes />
</Routes>
</div>
</Show>
</ErrorBoundary>
</Suspense>
</SessionProvider>
<Scripts />
</Body>
</Html>
);
}
It sort of works, though when you sign out, you have to refresh to show the signup
5 replies
SSolidJS
Created by jorge on 7/6/2023 in #support
Trying to modify a type from @auth/core
Hi there, I am trying to edit the DefaultSession type from @auth/core as such:
import { DefaultSession } from "@auth/core/types";

declare module '@auth/core/types' {
interface Session {
user: {
id: string;
} & DefaultSession['user'];
}
}
import { DefaultSession } from "@auth/core/types";

declare module '@auth/core/types' {
interface Session {
user: {
id: string;
} & DefaultSession['user'];
}
}
in types/@auth.d.ts However, I am getting this error when I run pnpm dev
An unhandled error occured: Error: No known conditions for "./types" specifier in "@auth/core" package
An unhandled error occured: Error: No known conditions for "./types" specifier in "@auth/core" package
Am I missing something? I'm not very familiar with .d.ts files and solid start, so I might be missing something.
2 replies
SSolidJS
Created by jorge on 5/24/2023 in #support
Conditional tailwind css using signal
Hi there, I am looking for a way to apply a tailwind css style to a div when the signal is set to true. Is that possible?
9 replies