Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use postgres function as second argument to set #49

Closed
rubymaniac opened this Issue · 9 comments

3 participants

@rubymaniac

I want to construct the following query:

UPDATE users SET password = crypt('my super awesome password', gen_salt('md5'))

and it is not obvious how I have to go in order to not have the crypt function to get interpreted as a string value. I do not want to use the usingValuePlaceholders option because it is deprecated. Is there any other way?

@hiddentao
Owner

Yep, you can use a custom value type. Just represent the crypt('my super awesome password', gen_salt('md5')) part as a CryptFunction class or something and then register that value type with squel along with a handler. Then everytime squel encounters an instance of that class it will pass it off to your custom handler to get the string representation.

@andreyvit

Nope, doesn't work for me:

squel = require('squel')

class RawSql
  constructor: (@sql) ->

squel.registerValueHandler RawSql, (rawSql) ->
  return rawSql.sql

squel.sql = (sql) -> new RawSql(sql)

console.log('%s', squel.insert().into('widgets').set('foo', 42).set('created_at', squel.sql('NOW()')))
# INSERT INTO widgets (foo, created_at) VALUES (42, 'NOW()')

What I need is an unquoted raw value. I think this absolutely must be a part of the library; pretty much every app requires access to NOW().

@hiddentao
Owner

@andreyvit That code works fine for me. I'm running against squel 2.0.0 on node 0.11.10

@andreyvit

@hiddentao By ‘works fine’, do you mean it produces this?

INSERT INTO widgets (foo, created_at) VALUES (42, NOW())

Anyways, obviously toString isn't the primary use case, and I cannot see how it can possibly work with toParam, given that you give all the output strings to the native driver as values.

@hiddentao
Owner

@andreyvit Yep, that's what I get when I run the code. Have you tried using it with toParam()?

@hiddentao
Owner

Also, just released v3.0.1 which should improve toParam() a little bit.

@hiddentao
Owner

Is this still an issue?

@andreyvit

No idea, I've stopped using squel. @rubymaniac?

@rubymaniac

Sorry I too stopped using squel. I have no idea if this is still an issue.

@hiddentao hiddentao closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.