Socket
Book a DemoInstallSign in
Socket

@getodk/slonik-sql-tag-raw

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@getodk/slonik-sql-tag-raw

Slonik SQL tag for constructing dynamic queries.

1.0.3-1
latest
Source
npmnpm
Version published
Maintainers
2
Created
Source

slonik-sql-tag-raw

Travis build status Coveralls NPM version Canonical Code Style Twitter Follow GitSpo Mentions

Slonik SQL tag for constructing dynamic queries.

Warning

There are no known use cases for generating queries using raw that aren't covered by nesting bound sql expressions or by one of the other existing query building methods. raw exists only as a mechanism to execute externally stored static queries (e.g. queries stored in files).

Usage

import {
  raw,
} from 'slonik-sql-tag-raw';

raw

(
  sql: string,
  values?: $ReadOnlyArray<PrimitiveValueExpressionType>
) => RawSqlTokenType;

Raw/ dynamic SQL can be inlined using raw, e.g.

sql`
  SELECT 1
  FROM ${raw('"bar"')}
`;

Produces:

{
  sql: 'SELECT 1 FROM "bar"',
  values: []
}

The second parameter of the raw can be used to bind positional parameter values, e.g.

sql`
  SELECT ${raw('$1', [1])}
`;

Produces:

{
  sql: 'SELECT $1',
  values: [
    1
  ]
}

Named parameters

raw supports named parameters, e.g.

sql`
  SELECT ${raw(':foo, :bar', {bar: 'BAR', foo: 'FOO'})}
`;

Produces:

{
  sql: 'SELECT $1, $2',
  values: [
    'FOO',
    'BAR'
  ]
}

Named parameters are matched using /[\s,(]:([a-z_]+)/g regex.

Keywords

postgres

FAQs

Package last updated on 16 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.