Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

named-placeholders

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

named-placeholders

sql named placeholders to unnamed compiler

  • 1.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2M
decreased by-13.87%
Maintainers
1
Weekly downloads
 
Created

What is named-placeholders?

The named-placeholders npm package is used to convert SQL query strings with named placeholders into a format that can be used with parameterized queries. This is particularly useful for preventing SQL injection attacks and making SQL queries more readable and maintainable.

What are named-placeholders's main functionalities?

Convert named placeholders to positional placeholders

This feature allows you to convert a SQL query with named placeholders into a query with positional placeholders, which can then be executed using a database client that supports parameterized queries.

const named = require('named-placeholders')();
const query = 'SELECT * FROM users WHERE name = :name AND age = :age';
const params = { name: 'John', age: 30 };
const [sql, values] = named(query, params);
console.log(sql); // 'SELECT * FROM users WHERE name = ? AND age = ?'
console.log(values); // ['John', 30]

Support for repeated placeholders

This feature allows you to use the same named placeholder multiple times in a query. The named-placeholders package will correctly replace all instances with the appropriate positional placeholders.

const named = require('named-placeholders')();
const query = 'SELECT * FROM users WHERE name = :name OR nickname = :name';
const params = { name: 'John' };
const [sql, values] = named(query, params);
console.log(sql); // 'SELECT * FROM users WHERE name = ? OR nickname = ?'
console.log(values); // ['John', 'John']

Support for array parameters

This feature allows you to use arrays as parameters in your SQL queries. The named-placeholders package will expand the array into the appropriate number of positional placeholders.

const named = require('named-placeholders')();
const query = 'SELECT * FROM users WHERE id IN (:ids)';
const params = { ids: [1, 2, 3] };
const [sql, values] = named(query, params);
console.log(sql); // 'SELECT * FROM users WHERE id IN (?, ?, ?)'
console.log(values); // [1, 2, 3]

Other packages similar to named-placeholders

Keywords

FAQs

Package last updated on 12 Jan 2023

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