Skip to content
getsentryPublic

About

A SQL-ish parser and formatter for syntax highlighting and pretty-printing.

Topics

Resources

Code of conduct

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

@sentry/sqlish

A SQL-ish parser and formatter for syntax highlighting and pretty-printing.

Installation

pnpm add @sentry/sqlish

For React formatting support, also install React:

pnpm add react

Usage

Parsing

import { SQLishParser } from '@sentry/sqlish';

const parser = new SQLishParser();
const tokens = parser.parse('SELECT id, name FROM users WHERE id = 42');

String Formatting

import { SQLishFormatter } from '@sentry/sqlish';

const formatter = new SQLishFormatter();
const formatted = formatter.toString('SELECT id, name FROM users WHERE id = 42');

You can also use the low-level string formatter directly:

import { SQLishParser, string } from '@sentry/sqlish';

const parser = new SQLishParser();
const tokens = parser.parse('SELECT id, name FROM users WHERE id = 42');
const formatted = string(tokens, { maxLineLength: 80 });

React Markup (optional)

Requires react as a peer dependency.

import { SQLishParser } from '@sentry/sqlish';
import { simpleMarkup } from '@sentry/sqlish/react';

const parser = new SQLishParser();
const tokens = parser.parse('SELECT id, name FROM users WHERE id = 42');
const highlighted = simpleMarkup(tokens);

return <div>{highlighted}</div>;

API

SQLishParser

  • parse(sql: string): Token[] — Parses a SQL-ish string into tokens

SQLishFormatter

  • toString(sql: string, options?): string — Parses and formats SQL as a pretty-printed string

Utility Functions

  • string(tokens: Token[], options?): string — Formats tokens as a plain string (low-level)
  • simpleMarkup(tokens: Token[]): React.ReactElement[] — Formats tokens as React elements with syntax highlighting (from @sentry/sqlish/react)

Development

# Install dependencies
pnpm install

# Build the project
pnpm run build

# Run tests
pnpm test

License

Apache-2.0

About

A SQL-ish parser and formatter for syntax highlighting and pretty-printing.

Topics

Resources

Code of conduct

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages