插件本地插件稳定版

SQL Query Builder

local_sqlquerybuilderKonrad Ebel

  • Moodle 4.1–5.1
  • 更新 2025-11-26

It enables other plugins to build SQL queries using a builder class.
The plugin allows you to write complex queries using a query builder for other plugins.
It is a library for other plugins and does not include any user features itself.
The query builder’s syntax is based on Laravel.
It makes writing SQL queries in Moodle easier.
For example it supports statements like:
$this->db = di::get(i_db::class);
$this->db->table(‘user’)->where(‘firstname’, ‘=’, ‘Paul’)->get();
But also more complex examples like:
$this->db = di::get(i_db::class);
$this->db->table(‘enrol’, ‘e’)
->distinct()
->join(‘user_enrolments’, [‘ue.enrolid’, ‘=’, ‘e.id’], ‘ue’)
->join(‘user’, [‘u.id’, ‘=’, ‘ue.userid’], ‘u’)
->select(‘ue.userid’)
->where(‘ue.status’, ‘=’, 0)
->where(‘u.deleted’, ‘=’, 0)
->where(‘u.suspended’, ‘=’, 0)
->where_currently_active(‘ue.timestart’, ‘ue.timeend’)
->order_asc(“ue.userid”)

返回插件目录