Skip to content

Commit

Permalink
feat: create escapeIdentifier utility
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jul 29, 2018
1 parent a1f7298 commit 71bb89a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/utilities/escapeIdentifier.js
@@ -0,0 +1,8 @@
// @flow

/**
* @see https://github.com/brianc/node-postgres/blob/6c840aabb09f8a2d640800953f6b884b6841384c/lib/client.js#L306-L322
*/
export default (identifier: string) => {
return '"' + identifier.replace(/"/g, '""') + '"';
};
1 change: 1 addition & 0 deletions src/utilities/index.js
@@ -1,5 +1,6 @@
// @flow

export {default as escapeIdentifier} from './escapeIdentifier';
export {default as mapTaggedTemplateLiteralInvocation} from './mapTaggedTemplateLiteralInvocation';
export {default as normalizeAnonymousValuePlaceholders} from './normalizeAnonymousValuePlaceholders';
export {default as normalizeNamedValuePlaceholders} from './normalizeNamedValuePlaceholders';
Expand Down
11 changes: 11 additions & 0 deletions test/utilities/escapeIdentifier.js
@@ -0,0 +1,11 @@
// @flow

import test from 'ava';
import {
escapeIdentifier
} from '../../src/utilities';

test('escapes a SQL identifier', (t) => {
t.true(escapeIdentifier('foo') === '"foo"');
t.true(escapeIdentifier('"foo"') === '"""foo"""');
});

0 comments on commit 71bb89a

Please sign in to comment.