crysalead-js / sql-dialect

SQL Builder
MIT License
6 stars 2 forks source link

Common Table Expressions #3

Closed esatterwhite closed 4 years ago

esatterwhite commented 5 years ago

I use common table expressions ( WITH, WITH RECURSIVE ) pretty heavily with postgres. I'm not seeing a way to do this. Would this need to be a part of the select statement. or would it need to be apart of dialect.

const subquery = dialect.statement('update').table('foo')...
const query = dialect.statement('select')

query
  .with(subquery)
  .from('x')
  .fields(...)
  .where()

Something like that? It feels like it'd need to be its own statement and built into a dialect maybe?

jails commented 5 years ago

Indeed it would require to have its own 'with' statement. So right now CTEs are not supported by this library out of the box but PR are welcome :wink:

esatterwhite commented 5 years ago

Well one or more ctes are legal on any SELECT, UPDATE or DELETE statement. Would it make sense for each statement to implement a with function?

We're building something with this currently. There will probably be some code for a PR in the near future

jails commented 4 years ago

Fixed in 4.1.0 release