brianc / node-sql

SQL generation for node.js
MIT License
1.05k stars 191 forks source link

Support Postgres JSON operators #148

Open litek opened 10 years ago

litek commented 10 years ago

Currently only -> is supported through column.key(). It would be great if ->>, #> and #>> could be added, I'm not entirely sure what would be a good name for them though.

Perhaps something like: ->> text(key)

> path([keys])

>> pathText([keys])

Or maybe: -> key(key) ->> key(key).text()

> path([keys])

>> path([keys]).text()

Ref: http://www.postgresql.org/docs/9.3/static/functions-json.html

derek-watson commented 10 years ago

:+1:

I like your first method signature, how about the following?

customer.select(customer.metadata.key('age')) 
# SELECT ("customer"."metadata" -> 'age') FROM "customer"

customer.select(customer.metadata.keyText('age')) 
# SELECT ("customer"."metadata" ->> 'age') FROM "customer"

customer.select(customer.metadata.path('{address,city}')) 
# SELECT ("customer"."metadata" #> '{address,city}') FROM "customer"

customer.select(customer.metadata.pathText('{address,city}')) 
# SELECT ("customer"."metadata" #>> '{address,city}') FROM "customer"
munro commented 10 years ago

This should be closed due to #151, correct?