select expression helper
I got this selectExpression that i use in many file
.select([
'e.id',
eventStartDate('e'),
eventEndDate('e'),
'e.title',
'e.type',
'e.status',
'e.banner',
'e.event_end_date as end_date',
'e.location',
'e.duration_in_minute',
'e.participant_count_limit',
'e.registration_date_limit',
'e.provider',
coordinates('e'),
sql<boolean>
is_full_of_participants(e)
.as('isFullOfParticipants'),
sql<string[]>get_event_sports(e.id)
.as('sports'),
])
how can i create a helper function in order to reuse it ?6 Replies
Might help you along the way, since I'd need some more context for your example.
I created the following helper:
I use this pattern to add some helper functions per entity I have.
This is how the helper is called:
thanks, but how to make the select query at the root select and not in a "sub item" ?
Solution
Follows pattern found in https://kysely.dev/docs/recipes/expressions#creating-reusable-helpers
Expressions | Kysely
An Expression is the basic type-safe query building block in Kysely. Pretty much all methods accept expressions as inputs. Most internal classes like SelectQueryBuilder and RawBuilder (the return value of the sql tag) are expressions themselves.
(bumping in case answer overflow made this thread hard to find)
thanks !