npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sql-lint

v1.0.0

Published

An intelligent SQL linter and checker

Downloads

3,660

Readme

sql-lint

NOTE: This project is maintained but it's sporadic when it's worked on. I have my fingers in about 304583409 pies and they're not all software related. Please keep raising issues/bug reports

Build Status

sql-lint will do sanity checks on your queries as well as bring errors back from the DB. If you worry about forgetting WHEREs on a DELETE or borking your data with unexpected characters, then sql-lint is for you.

A complete list of the checks it does is below.

Imgur

Imgur

Installation

npm i -g sql-lint
# or
yarn global add sql-lint

Or download a binary

Usage

sql-lint works on files, directories and stdin.

# Will lint all .sql files recursively from the current directory
sql-lint .

# Lints the create-person.sql file
sql-lint create-person.sql

# Lints stdin
echo 'DELETE FROM person;' | sql-lint

Programmatic Access

npm i sql-lint
# or
yarn add sql-lint
import sqlLint from 'sql-lint'

// using async/await

const errors = await sqlLint({
  sql: 'SELECT my_column FROM my_table',
})

// or using promise

sqlLint({ sql: 'SELECT my_column FROM my_table' }).then(errors => {
  for (const error of errors) {
    // do something
  }
})

Parameters

sql-lint accepts an object using the following interface as its only argument

{
  sql: string
  host?: string
  user?: string
  port?: number
  driver?: string
  prefix?: string
  password?: string
  verbosity?: number
}

Notes on some of the parameters

sql: can have multiple queries separated by ;

host: if host is not provided sql-lint will only perform checks that do not require a connection

driver: defaults to mysql

port: if port is not provided it will use the default port for the driver you are using

Output

sql-lint returns an array of objects with the following shape

{
  line: number
  error: string
  source: string
  additionalInformation: string
}

Editor Integration

If your editor supports external tools, then it supports sql-lint. Below is the list that have direct support for sql-lint either through plugins or configuration.

(Neo)Vim

(Neo)Vim can be configured to use sql-lint on .sql files.

Ale ships with sql-lint support out the box.

If you do not want to use a plugin, a much more lightweight solution is to run the following in an .sql file:

:!sql-lint %

VSCode

Inline SQL extension uses sql-lint to provide diagnostics for sql strings and optionally .sql files.

Checks

sql-lint comes with its own suite of checks. It also returns any errors from the SQL server you have connected to. Generally you'll find that the errors from sql-lint are more informative than those from the server. That said, you will still want errors from the server as it covers more cases and will catch things that sql-lint does not.

unmatched-parentheses

Shown when a query has an unbalanced amount of parentheses.

test/test-files//test.sql:16 [sql-lint: unmatched-parentheses] Unmatched parentheses.

missing-where

Shown when a DELETE statement is missing a WHERE clause.

test/test-files/test.sql:20 [sql-lint: missing-where] DELETE statement missing WHERE clause.

invalid-drop-option

Shown when an invalid option is given to the DROP statement.

test/test-files/test.sql:22 [sql-lint: invalid-drop-option] Option 'thing' is not a valid option, must be one of '["database","event","function","index","logfile","procedure","schema","server","table","view","tablespace","trigger"]'.

invalid-create-option

Shown when an invalid option is given to the CREATE statement.

:24 [sql-lint: invalid-create-option] Option 'test' is not a valid option, must be one of '["algorithm","database","definer","event","function","index","or","procedure","server","table","tablespace","temporary","trigger","user","unique","view"]'.

invalid-truncate-option

Shown when an invalid option is given to the TRUNCATE statement.

test/test-files/test.sql:26 [sql-lint: invalid-truncate-option] Option 'something' is not a valid option, must be one of '["table"]'.

invalid-alter-option

Shown when an invalid option is given to the ALTER statement.

test/test-files/test.sql:28 [sql-lint: invalid-alter-option] Option 'mlady' is not a valid option, must be one of '["column","online","offline","ignore","database","event","function","procedure","server","table","tablespace","view"]'.

odd-code-point

Shown when there are unsupported/unusual* code points in your code.

*This check came about whilst working Microsoft Excel. Microsoft likes to add a lot of zany characters which can subtly break your data without you realising.

test/test-files//test.sql:30 [sql-lint: odd-code-point] Unexpected code point.

invalid-limit-quantifier

Shown when you specify something other than a number to the LIMIT statement.

test/test-files//test.sql:32 [sql-lint: invalid-limit-quantifier] Argument 'test' is not a valid quantifier for LIMIT clause.

hungarian-notation

Shown when the string sp_ or tbl_ is present in the query.

test/test-files/test.sql:34 [sql-lint: hungarian-notation] Hungarian notation present in query

trailing-whitespace

Shown when a query has trailing whitespace.

test/test-files/test.sql:34 [sql-lint: trailing-whitespace] Trailing whitespace

Read more

To find out more, read the documentation