CSNW / sql-bricks

Transparent, Schemaless SQL Generation
http://csnw.github.io/sql-bricks
MIT License
204 stars 25 forks source link

sql() params don't work in fields or tables list #77

Open Suor opened 8 years ago

Suor commented 8 years ago
select('id', 'title', sql('ts_rank(tsv, plainto_tsquery($))', search))
    .from('place').where(...)
// SELECT id, title, ts_rank(tsv, plainto_tsquery($)) FROM place ...

select().from('place', sql('plainto_tsquery($) as query', search))
    .where(sql('tsv @@ query'))
// SELECT * FROM place, plainto_tsquery($) as query WHERE tsv @@ plainto_tsquery
Suor commented 7 years ago

Any news on this?

prust commented 7 years ago

@Suor: I recently went through the open issues & marked some easy ones as good first bug and bigger or non-backwards compatible ones with the 3.0 milestone. This is the only one that didn't fall into either camp.

I suspect it's not trivial, but not super-hard either, and I was hoping to make time to tackle it within the next few months. If you have time and inclination before then, a pull request would be welcome -- or if you just want to do some initial digging and see where the problem is or where the code will likely need to be changed.

w33ble commented 2 years ago

I just ran in to this when trying to do substitutions for selects with postgis. I don't know if it's any easier, but a utility function to just do a simple value replacement would be a workable alternative.

To use the the original example, I was thinking something like this, where sql.replace just does the string substitutions (without messing with the value indexes).

select('id', 'title', replace('ts_rank(tsv, plainto_tsquery($))', search))
    .from('place').where(...)