DavidLGoldberg / qolor

An atom package to color your queries!
https://atom.io/packages/qolor
MIT License
16 stars 3 forks source link
atom color highlight semantic sql sql-query

Qolor

Join the chat at https://gitter.im/qolor-atom/Lobby Build Status

An atom package to color your SQL queries!

Qolor applies semantic highlighting to your SQL queries by matching tables to their aliases.

Qolor in action!

All colors of tables are deterministic and based on their name. They will be the same on any Atom editor anywhere!

Qolor has a few outstanding issues but it's usable and I want to launch it in the spirit of MVP. I say it's usable because it doesn't throw errors or pop up the inspector. If you see it doing this please report ASAP. Please feel free to create issues of broken coloring cases with screen shots or text samples (remember to check out the TODO below and the open issues).

Installation

apm install qolor

Settings

Two stylistic flavors. Underline (default) or a border box. The border box is more of a placeholder for now. I only built it to facilitate pull requests etc.

Optional Keymap To Toggle

Go to Atom -> Open Your Keymap and enter the following:


'atom-workspace':
  'ctrl-alt-q': 'qolor:toggle'

# Careful, don't override your existing 'atom-workspace'!

How to Auto Associate File Types in Atom

Go to Atom -> 'Init Script...' and add in:


# This example associates all mustache files with 'SQL (Mustache)'.
atom.workspace.observeTextEditors (editor) ->
  if editor.getPath()?.match(/\.mustache$/)
    editor.setGrammar(atom.grammars.grammarForScopeName('source.sql.mustache'))

Prior Art / Related Works

I got the idea for Qolor while working with a large query. We all play a frustrating game of connect the dots while mentally parsing ("grokking") aliases to their tables. Colors can help you hunt down the aliases.

Later a friend pointed out that a lot of related work in the area of "semantic highligting" already exists! Although, I have yet to find one that does this semantic highlighting for SQL in this table to alias manner. Let me know if it does!

Here are some of the related links:

How it works

Qolor uses the language-sql grammar built into Atom (actually it evolved from textmate/sublime). The code performs a double pass. First pass for the table names and second pass for the aliases.

I don't know of any SQL parsers in node usable for this project.

The code is ugly. language-sql suffices for syntax coloring, but it's tokens aren't always accurate. I try to make a layer of rules on top.

It should work for most cases, but please report any issues.

Your performance should be unaffected because qolor utilizes the debounced api for observing the grammar and because well, computers are fast.

TODO

My other Atom package :)

My VS Code version of Jumpy :))