Skip to content

util.escapeValue #1387

Closed
Closed

Description

@chiluap

Hi there,

I was looking for a way to escape values by their type to make Bulk-INSERTS.

something like:

util.escapeValue(, [type]);

util.escapeValue('2017-07-26T14:07:35.106000', 'timestamp without time zone');
// => ('2017-07-26T14:07:35.106000')::timestamp without time zone
util.escapeValue('some unescaped text', 'text');
// => ('some unescaped text')::text
util.escapeValue('23', 'integer');
// => 23

does this exist here ?
Looked around found nothing...sorry

Thanks for the good work with node-postgres b.t.w.

maybe start with something like:

sqlEscape(value, type) {
        if (value === null || _.isEmpty(value)) {
            return '';
        }
        value = value.replace("'", "''");
        return "('" + value + "')::" + type;
 }

Activity

  1. vitaly-t commented on Jul 27, 2017

    @vitaly-t
    Contributor

    @chiluap you can use the method from here.

  2. charmander commented on Jul 27, 2017

    @charmander
    Collaborator

    Use arrays: #957 (comment)

  3. chiluap commented on Jul 28, 2017

    @chiluap
    Author

    @charmander: That's the trick. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions