Moodle Plugins directory: SQL Query Builder | Moodle.org
SQL Query Builder
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();
- 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
Comments