# sqliteformat

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

Latest version **0.0.8** (published 2023-05-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install sqliteformat
pnpm add sqliteformat
yarn add sqliteformat
bun add sqliteformat
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2023-05-03 |
| First published | 2023-05-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.0.0 |
| Dependencies | 0 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | adilovcode |

## Links

- npm: https://www.npmjs.com/package/sqliteformat
- Repository: https://github.com/adilovcode/sqliteformat
- Homepage: https://github.com/adilovcode/sqliteformat#readme
- Issues: https://github.com/adilovcode/sqliteformat/issues
- npm.io page: https://npm.io/package/sqliteformat

## Recent versions

- 0.0.8 (latest) — 2023-05-03
- 0.0.7 — 2023-05-03
- 0.0.6 — 2023-05-03
- 0.0.5 — 2023-05-02
- 0.0.4 — 2023-05-02
- 0.0.3 — 2023-05-02
- 0.0.2 — 2023-05-02
- 0.0.1 — 2023-05-02

## README

# 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

```javascript
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

---
_Source: https://npm.io/package/sqliteformat · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
