MariaDB Mode for CodeMirror

I needed a SQL editor written in JavaScript for a tool I use to rapidly modify my databases. I found CodeMirror. It works great, and it’s used by a number of important projects. The code is released with a MIT license (I would prefer AGPL3, but it’s ok).

CodeMirror supports many languages, and language scripts are called Modes. I tried the MySQL mode but… well, to be honest, I didn’t like it. Maybe I am not lucky, but the first statements I wrote (DELIMITER and TRUNCATE) were not highlighted. Also, floating point numbers were not highlighted.

So, I wrote a new mode and put it on GitHub: MariaDB:

First, I re-worked the code. Now it’s in Strict Mode, and it uses types more strictly. Then, I fixed a couple of minor bugs in MySQL mode: ‘–‘ comments did not require a space, and backticks could be escaped in identifiers with a ‘\’.

Then, I added something:
* a lot of new keywords from MySQL and MariaDB;
* float numbers (including esponents)
* variables (all syntaxes);
* bin and hex (all syntaxes);
* all types of comments;
* ‘?’ (for prepared statements).

Limitations? Well, it does not support automatic indentation, and many other features that maybe should be supported. However, I just wrote this mode to improve a tool I use. I may improve it if there is interest around it, but I will not work on it if I’m not sure it makes sense.

If you use MariaDB Mode and you have some comments/requests, let me know. If you improve it, please do a Pull Request on GitHub repo.



Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s