couincouin007
couincouin007
Explore posts from servers
DTDrizzle Team
Created by couincouin007 on 12/18/2023 in #help
getPost() / getPosts() / ... what's your opinion? + any TS magician here :) ?
Hello! I was thinking of creating functions which will execute my queries, instead of putting all queries in my components. With that in place, I would be able to switch between Drizzle with any other query build / orm if I would like. To put it simply:
// lib/fetchers/post.ts
export async function getPost(id: Post["id"], options = {}): Promise<Post | undefined> {
const data = await db.query.post.findFirst({
where: eq(post.id, id),
...options
})

return data
}


// component.ts
export async function Component() {
const post = await getPost(1);

return <h1>{post.title}</h1>
}
// lib/fetchers/post.ts
export async function getPost(id: Post["id"], options = {}): Promise<Post | undefined> {
const data = await db.query.post.findFirst({
where: eq(post.id, id),
...options
})

return data
}


// component.ts
export async function Component() {
const post = await getPost(1);

return <h1>{post.title}</h1>
}
1. What do you think about this approach? i think it's convenient, abstraction does not seem overkilled, and I think it's quiet common, but I don't have seen it in tutorials / courses, but I think it's cleaner and more maintanable than putting queries everywhere in your code 2. I needed to add some types (id param + function return) to make it better to use, but I still don't know how or if it would be possible to type the options object which should take all params accepted in the findFirst method (such as columns, where...)
19 replies
TTCTheo's Typesafe Cult
Created by couincouin007 on 12/8/2023 in #questions
Conflict between shadcn/ui components and @typescript-eslint/no-empty-interface
I have linting errors while using shadcn/ui components because there are some empty interfaces defined extending other supertype interfaces, as : interface CommandDialogProps extends DialogProps {} The @typescript-eslint/no-empty-interface rule prevent the build saying it's an error. I've found that I can configure my eslint rules to satisfy it with:
"@typescript-eslint/no-empty-interface": [
"error",
{
allowSingleExtends: true,
},
],
"@typescript-eslint/no-empty-interface": [
"error",
{
allowSingleExtends: true,
},
],
Did you solve this error with another solution? Even if I understand the value of this rule, I think I'm not alone to use shadcn/ui and with the ESLint T3 stack config, this error is boring... On the same subject, the @typescript-eslint/consistent-type-imports rule displays warnings also with shadcn/ui components...
6 replies