CodeMirror: How add tables to sql-hint?

mamcx picture mamcx · Nov 16, 2013 · Viewed 8.1k times · Source

I can't figure how add tables to codemirror. I have sql-hint.js included, and work for keywords but don't understand how add tables and columns...

Answer

Matthew Simon Cavalletto picture Matthew Simon Cavalletto · Nov 22, 2013

Sadly, this does not appear to be documented anywhere.

With some trial and error I was able to figure out that you can pass in a structure of table and column names as options when invoking the hinter, like this:

CodeMirror.commands.autocomplete = function(cm) {
    CodeMirror.showHint(cm, CodeMirror.hint.sql, { 
        tables: {
            "table1": [ "col_A", "col_B", "col_C" ],
            "table2": [ "other_columns1", "other_columns2" ]
        }
    } );
}