._perry_.
._perry_.
TTCTheo's Typesafe Cult
Created by ._perry_. on 7/5/2023 in #questions
Weird type errors with next.js and drizzle
//when I use
export const dynamicParams = false;
//or
export const dynamicParams = true;
//when I use
export const dynamicParams = false;
//or
export const dynamicParams = true;
Next gives me these errors: - "false" is not a valid value for the "dynamicParams" option. - "true" is not a valid value for the "dynamicParams" option. Also, in this code the function getPostFromSlug is returning a weird type
export type ModifyKeys<T, R> = Record<keyof T, R>;
export const findFirstPost = cache(db.query.posts.findFirst);

//this function returns Promise<{} | undefined> for some reason
export const getPostFromSlug = async (
slug: string,
columns: Partial<ModifyKeys<Post, boolean>> = {
slug: false,
publishedAt: false
}
) => {
return await findFirstPost({
columns,
where: eq(posts.slug, slug)
});
};
export type ModifyKeys<T, R> = Record<keyof T, R>;
export const findFirstPost = cache(db.query.posts.findFirst);

//this function returns Promise<{} | undefined> for some reason
export const getPostFromSlug = async (
slug: string,
columns: Partial<ModifyKeys<Post, boolean>> = {
slug: false,
publishedAt: false
}
) => {
return await findFirstPost({
columns,
where: eq(posts.slug, slug)
});
};
2 replies
TTCTheo's Typesafe Cult
Created by ._perry_. on 7/4/2023 in #questions
Using cache with drizzle
How exactly would I use cache with the select from drizzle? if it was just the method it would be simple, but it returns from that returns where and there's all the other methods. How the hell am I supposed to do this?
46 replies
TTCTheo's Typesafe Cult
Created by ._perry_. on 7/4/2023 in #questions
Making a enum/union type like in prisma, but with drizzle
I have this a role pgEnum and I want to make a enum type that is also a union type, like what happens in prisma when you make a enum
export const role = pgEnum("role", ["USER", "ADMIN"]);

// This is what i'm currently using
export enum Role {
user = "USER",
admin = "ADMIN"
}
export const role = pgEnum("role", ["USER", "ADMIN"]);

// This is what i'm currently using
export enum Role {
user = "USER",
admin = "ADMIN"
}
With prisma I would be able to do this on the schema
enum Role {
USER,
ADMIN
}
enum Role {
USER,
ADMIN
}
and use it like this inside my typescript
import { Role } from "@prisma/client";

// This has autocomplete functioning perfectly
const firstExample: Role = "USER";
const secondExample: Role = "ADMIN";
const thirdExample: Role = Role.USER;
const fourthExample: Role = Role.ADMIN
import { Role } from "@prisma/client";

// This has autocomplete functioning perfectly
const firstExample: Role = "USER";
const secondExample: Role = "ADMIN";
const thirdExample: Role = Role.USER;
const fourthExample: Role = Role.ADMIN
9 replies