_tweak^prone
_tweak^prone
Explore posts from servers
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
Great - let me know if the usecase makes sense. But its super type-important 🙂
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
(and it will have to be an "any" type, or you have to make a 1:1 copy type of whatever you return from the drizzl db.table.select.leftjoin)
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
Problem is, if you take Drizzle results and parse it into a component, when you use it in the component the type will by definition be "lost", as theres no relation from the component to where you use the component.
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
The above example is a type containing SOME fields from "comment" type and SOME fields of "user" type - in a mixed type / result from the database. In prisma you can do commentGetPayload< your object that you pass into prisma db call without actually calling the database > and that will return a type that you can use to Type your parameters.
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
yearh, but sadly that doesnt solve the problem :/ it deosnt take relations into account
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
its just - to me drizzlekit seems more like prisma studio and push/pull - not type-generation
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
So for example, lets say i have this Drizzl:
const comments = await db.select(
{
uid: forum_thread_items.uid,
user_id: forum_thread_items.user_id,
content: forum_thread_items.content,
is_spam: forum_thread_items.is_spam,
version: forum_thread_items.version,
created_at: forum_thread_items.created_at,
user: {
id: users.id,
username: users.username,
slug: users.slug,
},
})
.from( forum_thread_items )
.where( eq( forum_thread_items.forum_thread_id, forum_thread_id ) )
.leftJoin( users, eq( forum_thread_items.user_id, users.id ) )
.offset( ( page - 1 ) * pageSize )
.limit( pageSize )
const comments = await db.select(
{
uid: forum_thread_items.uid,
user_id: forum_thread_items.user_id,
content: forum_thread_items.content,
is_spam: forum_thread_items.is_spam,
version: forum_thread_items.version,
created_at: forum_thread_items.created_at,
user: {
id: users.id,
username: users.username,
slug: users.slug,
},
})
.from( forum_thread_items )
.where( eq( forum_thread_items.forum_thread_id, forum_thread_id ) )
.leftJoin( users, eq( forum_thread_items.user_id, users.id ) )
.offset( ( page - 1 ) * pageSize )
.limit( pageSize )
This gets the comments and merges in the "user" type with a leftjoin I make a component: <ShowComment comment={...}> And i want the TYPE of the prop "comment" in my component props to be exactly one of the returntypes of the above drizzl. So i go like this:
const ShowComponent = (props:{
comment: ????
}) =>
const ShowComponent = (props:{
comment: ????
}) =>
Can Drizzlekit give me "????" ?
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
this means i can use ´PostComponentMainType` as my "requred type" in a function props for example
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
What i meant was this: Prisma has this:
export const PostComponentMainInclude = {
include: {

written_by_user: {
select: {
slug: true,
username: true,
}
},
submitted_by_user: {
select: {
slug: true,
username: true,
}
},
edited_by_user: {
select: {
slug: true,
username: true,
}
},
via: {
select: {
name: true,
}
},

forum_thread: {
include: {
_count: { select: { items: true } },
forum: {
select: {
title: true,
slug: true,
},
},
}
}
},
};
export type PostComponentMainType = Prisma.postsGetPayload<typeof PostComponentMainInclude>
export const PostComponentMainInclude = {
include: {

written_by_user: {
select: {
slug: true,
username: true,
}
},
submitted_by_user: {
select: {
slug: true,
username: true,
}
},
edited_by_user: {
select: {
slug: true,
username: true,
}
},
via: {
select: {
name: true,
}
},

forum_thread: {
include: {
_count: { select: { items: true } },
forum: {
select: {
title: true,
slug: true,
},
},
}
}
},
};
export type PostComponentMainType = Prisma.postsGetPayload<typeof PostComponentMainInclude>
Its the Typescript-type-definition of the Payload call you are about to make
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
im not sure i understand - this is more of a Prisma Studio thing right?
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
Like prisma has
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
do you know if theres anyway to get the Type-definition returned by a Drizzl-call ? So that it can be used as a parameter for a function (for example)
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
yearh, but i enjou the joins. the control 🙂
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
Very nice ! I like drizzl as its much closer to Laravels Eloquent.
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
Thanks a bunch m8 ! Hope this hold ! And what a bizarre thing 1
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
at the moment yes, but i will have to see it over the course of hours now
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
I will have to test this quite a bit more but it seems specifiying the same content in an object, instead of in a connection string.. fixed it 😮
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
The shot in the dark seemed to work. Let me try with connectionString instead
75 replies
TTCTheo's Typesafe Cult
Created by _tweak^prone on 7/30/2023 in #questions
Astro + DrizzleORM => trouble
I can try with specifying host/user/db instead of connectionstring. 2 secs
75 replies