TheMelonAssassin
Explore posts from serversTyping enums
First of all, I still really enjoy using Kysely, great library!
I have the following pattern for
enums
. I create the role
table as an "enum" table (which I got from another help post I was reading earlier) and add it as an foreign key to the teacher
table.
I also have the ROLES enum
to use across my back-end for various purposes
When I define the types for this table I do the following:
This works for typesafety of course, but I'd like for role
to be only values of the ROLES enum
.
Does it make sense to just change it from string
to Role
or am I missing something4 replies
DTDrizzle Team
•Created by TheMelonAssassin on 12/12/2024 in #help
Defining nested types with Drizzle Zod
What would be the correct way to create nested types with drizzle-zod here?
I have an acccount table like this:
And a townhall table like this:
How can I make sure the type comes back like this? That's the type I receive from my query and I need it to define my
tanstack-table
columns
I have the omit part down:
1 replies
Making Updateable<X> fields required
Excuse me if this has already been posted, but I recently turned on strict mode after completing my migration to TS and I'm struggling to make certain fields required when updating an entity.
When I hover over
UpdateableActivity
it shows:
but hovering over Updateable
shows:
if possible I'd like it to be something like:
https://kyse.link/MA3jQ is my playground link if that helps!6 replies
Issue with how timestamptz is returned depending on main or subquery
I'm running into the following issue where my date is returned in two different ways. Date is a
timestamptz
type column
When I grab the lesson as followed:
I receive "date": "2024-09-13T22:00:00.000Z"
When I use a subquery like this:
I receive "date": "2024-09-14T00:00:00+02:00"
15 replies
Creating helper functions
I've gotten to the point in my application where a lot of the objects I'm building in my queries are returning in other queries.
In the following example I'd like to extract the module (with color) into something I can use in other queries.
I've been trying to find the correct (and working) way to this
14 replies
Issue with select
How would I handle doing what I'm doing in the raw part during the select?
I get the following error:
No overload matches this call.
Overload 1 of 3, '(selections: readonly SelectExpression<Database & { townhallDistribution: { level: number; amount: string | number | bigint; }; }, "clan">[]): SelectQueryBuilder<Database & { ...; }, "clan", { ...; }>', gave the following error.
Type 'RawBuilder<unknown>' is not assignable to type 'SelectExpression<Database & { townhallDistribution: { level: number; amount: string | number | bigint; }; }, "clan">'.
Type 'RawBuilder<unknown>' is missing the following properties from type 'DynamicReferenceBuilder<any>': #private, dynamicReference, refType
Overload 2 of 3, '(callback: SelectCallback<Database & { townhallDistribution: { level: number; amount: string | number | bigint; }; }, "clan">): SelectQueryBuilder<Database & { ...; }, "clan", { ...; }>', gave the following error.
Argument of type '(string | RawBuilder<unknown>)[]' is not assignable to parameter of type 'SelectCallback<Database & { townhallDistribution: { level: number; amount: string | number | bigint; }; }, "clan">'.
Type '(string | RawBuilder<unknown>)[]' provides no match for the signature '(eb: ExpressionBuilder<Database & { townhallDistribution: { level: number; amount: string | number | bigint; }; }, "clan">): readonly SelectExpression<Database & { ...; }, "clan">[]'.
Overload 3 of 3, '(selection: SelectExpression<Database & { townhallDistribution: { level: number; amount: string | number | bigint; }; }, "clan">): SelectQueryBuilder<Database & { ...; }, "clan", { ...; }>', gave the following error.
Argument of type '(string | RawBuilder<unknown>)[]' is not assignable to parameter of type 'SelectExpression<Database & { townhallDistribution: { level: number; amount: string | number | bigint; }; }, "clan">'.ts(2769)
14 replies
Issue with migrating from knex
I've recently learned about Kysely and how it is very compatible with TS compared to Knex.
I'm also very new to coding in general and have been following the structure I was taught at school earlier this year but I'm struggling right now to migrate the file that initializes data and shuts it down.
If anyone would be so kind to help me figure out how to move this from Knex to Kysely!
5 replies