Search code examples
autocompletecodemirror

CodeMirror: How add tables to sql-hint?


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...


Solution

  • 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" ]
            }
        } );
    }