Skip to content

util.escapeValue #1387

Closed
Closed
@chiluap

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;
 }

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