SQL syntax highlight
A simple and lightweight syntax highlighting library for SQL
What's it all about?
SQL Highlight is a small package that highlights SQL queries. It can output to both the terminal with Unicode escape sequences, as well as to normal HTML. Oh, and there are no external dependencies 😉
Install via Yarn:
yarn add sql-highlight
Install via NPM:
npm install sql-highlight
Note that we're using ES6 import statements here. Usage with
requireworks just as well.
In its most basic form:
const sqlString = "SELECT `id`, `username` FROM `users` WHERE `email` = 'firstname.lastname@example.org'"const highlighted =console
const sqlString = "SELECT `id`, `username` FROM `users` WHERE `email` = 'email@example.com'"const highlighted =documentbodyinnerHTML += highlighted
The following options may be passed to the
||Set to true to render HTML instead of Unicode.|
||Prefix to prepend to classes for HTML span-tags. Is appended with entity name.|
||See below*||What color codes to use for Unicode rendering.|
colors option default value
keyword: '\x1b[35m' // SQL reserved keywordsfunction: '\x1b[31m' // Functionsnumber: '\x1b[32m' // Numbersstring: '\x1b[32m' // Stringsspecial: '\x1b[33m' // Special charactersbracket: '\x1b[33m' // Brackets (parentheses)
- Fork it (https://github.com/scriptcoded/sql-highlight/fork)
- Create your feature branch (
git checkout -b feature/fooBar)
- Commit your changes (
git commit -am 'Add some fooBar')
- Push to the branch (
git push origin feature/fooBar)
- Create a new Pull Request
Malcolm Nihlén - firstname.lastname@example.org
Distributed under the MIT licence. See
LICENCE for more information.
This was initially a fork from https://github.com/pomahtuk/sequilize-highlight. The repo wasn't being updated, NPM wasn't serving the latest version and there was a severe memory leak. Though the latest version now exists on NPM, issues still persist. This repo serves to address those problems, as well as providing a cleaner interface that's not bound to Sequelize.
With version 3.0.0 the library was almost completely rewritten, which leaves very little similarity with the original repo.