Socket
Socket
Sign inDemoInstall

sqliteformat

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sqliteformat

A utility function for merging SQL strings with placeholders and handling single quotes for SQLite.


Version published
Weekly downloads
11
increased by83.33%
Maintainers
1
Install size
6.00 kB
Created
Weekly downloads
 

Readme

Source

sqliteformat

A utility function for merging SQL strings with placeholders and handling single quotes for SQLite.

format(sql: string, parameters: any[]): string

Merges the provided SQL string by replacing placeholders (?) with corresponding values from the parameters array. This function handles single quotes in parameter values, ensuring proper formatting for SQLite.

Parameters

  • sql (string): The SQL string with placeholders to be merged.
  • parameters (array): An array of values to replace the placeholders in the SQL string.

Returns

  • result (string): The formatted SQL string with replaced placeholders.

Throws

  • Error - If the number of parameters does not match the number of placeholders in the SQL string.
  • Error - If an invalid start index is encountered during replacement.

Example

import { format } from 'sqliteformat';

const sql = "SELECT * FROM users WHERE name = ? AND age > ?";
const parameters = ['John Doe', 30];

const formattedSql = format(sql, parameters);
console.log(formattedSql);
// Output: SELECT * FROM users WHERE name = 'John Doe' AND age > 30

FAQs

Last updated on 03 May 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc