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...
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" ]
}
} );
}
I know that this question is somewhat old but..I found an interesting way, valid in 4.3 release (I don't know anything about older releases): Just add the "CodeMirror.hint.sql" value (without quotes, as its a function) as "hint" option and add the "tables" object as a sub-object defined in "hintOptions" object.
Something like:
CodeMirror.fromTextArea(document.getElementsByTagName("textarea")[0], {
mode: "text/x-sql",
extraKeys: {"Ctrl-Space": "autocomplete"}, // To invoke the auto complete
hint: CodeMirror.hint.sql,
hintOptions: {
tables: {
"table1": [ "col_A", "col_B", "col_C" ],
"table2": [ "other_columns1", "other_columns2" ]
}
}
});
That's it. Note that the "extraKeys" is absolutely not needed, but I found it to be great to test the autocomplete more easily. =)
Good luck. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With