SQL Query Builder

Maintained by Konrad Ebel
It enables other plugins to build SQL queries using a builder class.
Price option: Free

Supports Moodle 4.1-5.1 See all versions
Latest release: 8 months ago
Installations: 3
Downloads (last 90 days): 14

Frankenstyle name: local_sqlquerybuilder
Local plugins

Description

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")
            ->get();

Todos

  • Allow subqueries in where statement
  • Allow equal functions (case sensitive, text functions ...)
  • Add union function
  • Provide more raw methods to make the plugin more flexible
  • JSON Functions
  • Update functionality
  • Delete functionality
  • Create functionality

Contributors

Awards

Automated testing support