Socket
Socket
Sign inDemoInstall

slonik-sql-tag-raw

Package Overview
Dependencies
Maintainers
0
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slonik-sql-tag-raw

Logs Slonik queries.


Version published
Weekly downloads
5.9K
decreased by-18.5%
Maintainers
0
Weekly downloads
 
Created
Source

slonik-sql-tag-raw

NPM version Canonical Code Style Twitter Follow

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

FAQs

Package last updated on 24 Aug 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc