This is just an idea…
TL;DR
I’ve been working on API to work with tables for some time (still huge VIP, not something anybody should really see atm., sorry), because for example we still do not have group by
and aggregations etc. I can call it like this (the SQL
is the custom table API):
${SQL(query[[...]]) -- transform query results by calling `from_table()` constructor
:where(...) -- apply some metamethods on internal data
:select(...)
:group_by(...)
:order_by(...)
:limit(...)
:execute(...) -- execute accumulated plan
:to_table(...) -- and return normal Lua table back
}
The arguments to the SQL
functions are mostly key names, key/value pairs or functions (just to clarify the idea).
Now, if the query
itself became Lua callable table (via the __exec
metamethod), we could just extend it in any way we like to and it will become even much nicer:
${query[[...]]
:where(...)
:select(...)
:group_by(...)
:order_by(...)
:limit(...)
:execute(...)
:to_table(...)
}
The most usable methods may be delivered (or not) in standard library and users could inspire from them or replace them or do whatever they like to do with the query
table. And, it won’t be breaking change at all! The query string will get parsed and it could use the internal metamethods to evaluate it and those metamethods could be extended or replaced by users, if needed. By default, everything will just work as it works now.
It’s just an idea, I can live without it easily.