kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.47k stars 267 forks source link

support for functions in selectFrom, e.g. GENERATE_SERIES #931

Closed mattkrick closed 6 months ago

mattkrick commented 6 months ago

Love this project! Thanks for all your work on it. I wanted to see if there's any interest in supporting functions in selectFrom.

Here's my example query:

SELECT
  NEXTVAL('"mySequence"')
FROM
  GENERATE_SERIES(1, 1000) 

To achieve that today, the closest I could get without pulling too many escape hatches is

db.selectFrom(sql.raw('generate_series(1,1000)'))
.select((pg) => pg.fn<number>('NEXTVAL', [sql.lit('"mySequence"')]).as('seqId'))
.execute()

ideally, it'd be nice to get the function params outside of the raw sql:

// error! doesn't work
db.selectFrom((eb) => eb.fn('generate_series', [1,1000]))

What do you think? If this is possible today, please let me know!

koskimas commented 6 months ago

Already supported. https://kyse.link/y5j6s