sql-log-prettifier
v0.2.0
Published
SQL query prettifier for your favorite logger
Maintainers
Readme
SQL log prettifier
SQL query prettifier for your favorite logger
Usage
npm install sql-log-prettifier
# or
yarn add sql-log-prettifierRequires Node.js 20 or newer. Ships both ESM and CommonJS builds, so you can
either import or require sql-log-prettifier:
import { prettify } from 'sql-log-prettifier';
// const { prettify } = require('sql-log-prettifier');
const unformattedAndUglySql = `SELECT * FROM custom_table WHERE id = 1 AND name = 'Test'`;
console.log(prettify(unformattedAndUglySql));Output will look something like this:
Settings
prettify function accepts settings as the second argument.
Default settings are:
const defaultSettings = {
format: true,
noColors: false,
settings: {
functions: {
color: '#ff5555',
modifiers: ['bold'],
},
keywords: {
color: '#ff5555',
modifiers: ['bold'],
},
operators: {
color: '#91B859',
modifiers: ['bold'],
},
strings: {
color: '#FFFFFF',
},
numbers: {
color: '#50fa7b',
},
},
};TODO:
- Add examples for popular loggers (
pino,winston) - Anything else that needs to be done :construction_worker:
Changelog
See CHANGELOG.md. Note that 0.2.0 requires Node.js 20+ and
is ESM-first; see the entry for the full list of breaking changes.
Development
sql-log-prettifier is built with tsup and tested with
vitest.
# Rebuild on change
npm run dev
# Run the tests
npm test
# Type check and lint
npm run typecheck
npm run lint
# Build
npm run buildContributing
All contributions are welcome.
License
MIT @ Zdravko Ćurić (zcuric)
