LUA Support For MySQL Command Line
Contents |
[edit] Adding Lua support to MySQL command line client
This is part of the Summer of Code 2008 project proposals.
[edit] Notes by KishoreKumar Bairi
[edit] Purpose of the project
This gives more flexibility to the user by providing him a feature to execute a program(written by him in lua) I feel this feature serves the same purpose as Shell Scripting in Unix or m-file programs in matlab. SQL file is also an executable script, but it is just a QUERY language and its not like a full fledged programming lanugage and so there comes the need for proper programming environment and this project is going to provide it. since we are adding support of a programming language. It enables user to build applications using this programming language and hence it leads to the personalization of mysql interface.
[edit] Why only LUA?
LUA is proven to be fast,portable,small yet powerful and most importantly * Embeddable*. It is easy to extend Lua with libraries written in other languages. It is also easy to extend programs written in other languages with Lua.
[edit] How it works?
- user issues the command for lua script execution.
- lua interpreter will be invoked.(which is *lua.c* file as mentioned in documentation of lua)
- while executing the script it builds the mysql command.
- and now we call the same functions of mysql library which are called when that built command was directly given on command line client.
- So, ultimately here we are doing the same thing but prepending the process with an additional step.
- (*This is just my understanding. **Please correct me if am wrong. **)*
[edit] How this can be done?
- firstly I should add a feature to command line client to invoke interpreter when proper command for execution of lua script is given.
- next step is regarding Lua library and interpretation. The library is available from Lua and Interpreter is also written by them
- It depends on us if we are willing to use their Interpreter of write our own from scratch(I feel its useless to reinvent the wheel).
- In the interpreter we have to add functionality to hand over the control to an intermediate(new) program(to be written).
- this new program maps the command command handed by interpreter to the mysql functionality which is supposed to be executed.
- (*am I right?)*
[edit] Notes by Giuseppe Maxia
To add Lua power to the MySQL client, you need first to set the goals and design the interface. I am brainstorming here:
[edit] Goals
- extending functionality, for example:
- adding loops to the command line
- adding aliases for commands (e.g. ls for show tables)
- creating smart user variables
- using arrays in the language
- storing and retrieving macros
[edit] Interface ideas
The above features can be transparent, and be detected by a query parser (e.g. a syntax for loops can just look like SQL) or they can require special keywords (e.g. to execute a Lua script).
If you want to implement Lua scripts, it would be a good idea to implement some objects that can be exposed to the scripts with specific function hooks (like MySQL Proxy does).