I use Kysely with a PostgreSQL database. In one of my tables. I have a key of type timestamp without time zone[]
.
The generated type:
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
export interface RateLimiting {
action_id: string;
timestamps: Timestamp[];
user_id: string;
}
this puts a list of Timestamp
s into timestamps
, but from my knowledge, that is improper use of ColumnType
.
When doing a query, the following happens:
const limit = await db.selectFrom('rate_limiting')
.selectAll()
.where('user_id', '=', ctx.user.id)
.where('action_id', '=', action)
.executeTakeFirst();
typeof limit?.timestamps[0]
this returns one of the Timestamp
s as is, so now we are working with a ColumnType
instead of Date
(the type in this example has __insert__
, __select__
and __update__
properties)
I created a utility type for this:
type List<T> = T extends ColumnType<infer S, infer I, infer U> ? ColumnType<S[], I[], U[]> : never;
export interface RateLimiting {
action_id: string;
timestamps: List<Timestamp>;
user_id: string;
}
I hope this is helpful, and thanks for the work that's been done here to make the Kysely experience better. I would love to commit a fix straight to the repo, but I'm not very experienced with this kind of stuff, only TypeScript. It'd be appreciated if a more experienced maintainer looks into the actual generation of such types.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too