Hacker News Front Page · remywang ·
Lua as a Query Language
El autor presenta Prela, un lenguaje de consultas dinámicas construido con Lua que genera nodos AST para que un backend en Rust los procese, evitando escribir un parser y el costo de compilar cada consulta con Rust. La propuesta aprovecha operadores sobrecargados, variables locales y closures para expresar filtros, agrupaciones, proyecciones y agregaciones; un ejemplo de TPC-H muestra cómo puede reducir la repetición y hacer explícitos los joins. El enfoque evita ejecutar una closure de Lua por cada fila, pero requiere precauciones para impedir la ejecución de código arbitrario, y el prototipo todavía es experimental.
Somehow I developed an allergy to writing parsers, so severe that I made up an entire query language (called Prela) just to avoid having to parse SQL. Prela itself turned out to be very nice, but there is one problem: it's not really a query langauge. It's just a bunch of Rust types and methods that give the feel of a query language. On one hand that's very convinient, because it means all the tooling built for Rust, including type checking, syntax highlighting, go-to-definition, etc., all work for Prela immediately. On the other hand, every query is compiled by rustc which usually takes even more time than executing the query itself... That's fine if the same query is meant to run again and again, but would be too much overhead for ad hoc queries.