Query Builder for Moodle

Query Builder for Moodle

by Konrad Ebel -
Number of replies: 1

Hallo liebe Moodle-Entwickler,

Ich finde Datenbankabfragen (Queries) werden in Moodle schnell unübersichtlich – vor allem, wenn sie komplex sind oder viele Tabellen betreffen. Es muss genau darauf achten, dass die Abfragen mit allen unterstützten Datenbanken (z. B. MySQL, PostgreSQL, MSSQL) funktionieren. Das kann viel Zeit kosten, weil man oft in der Moodle-Dokumentation oder im Code nachsehen muss, wie man bestimmte Dinge richtig umsetzt.

Ein Query Builder, wie man ihn z. B. aus Laravel kennt, könnte hier viel Arbeit abnehmen. Mit so einem Tool könnten Abfragen einfacher, lesbarer und sicherer gebaut werden – ohne direkt SQL schreiben zu müssen. Das würde nicht nur die Lesbarkeit und Wartbarkeit von Moodle-Plugins verbessern, sondern auch helfen, die Kompatibilität mit verschiedenen Datenbanken automatisch sicherzustellen.

LG Konrad Ebel

---

Hello dear Moodle developers,

I find that database queries in Moodle quickly become confusing—especially when they are complex or involve many tables. Careful attention must be paid to ensure that queries work with all supported databases (e.g., MySQL, PostgreSQL, MSSQL). This can be very time-consuming, as you often have to look up how to implement certain things correctly in the Moodle documentation or in the code.

A query builder, such as the one found in Laravel, could save a lot of work here. With such a tool, queries could be built more easily, more legibly, and more securely—without having to write SQL directly. This would not only improve the readability and maintainability of Moodle plugins, but also help to automatically ensure compatibility with different databases.

Best regards, Konrad Ebel

Translated with DeepL.com (free version)

In reply to Konrad Ebel

Re: Query Builder for Moodle

by Marcus Green -
A full new query builder would be a big task. I have been working on enhancing the existing and undermaintained Configurable reports plugin. I have a branch that pulls in the tables and columns from the underlying install.xml files and offers "intellisense" when creating sql queries. This works quite nicely but I would like to do more, e.g. put the { and } round table names and understand the PK/FK relationships. However to do that means transitioning to CodeMirror6 as the CodeMirror5 I have is obsolete.

https://github.com/marcusgreen/moodle-block_configurablereports/tree/sqlhints
If anyone is interested.