• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extending \CodeIgniter\Database\MySQLi\Builder possible?

#1
More questions on CI3 -> CI4...
In my old project I use SQL_CALC_FOUND_ROWS to query the database for the total count of records while doing a WHERE/LIMIT query. I need to LIMIT the queries to keep the frontend UI happy with huge datasets. I should only insert SQL_CALC_FOUND_ROWS if there is a WHERE clause in the SQL query, otherwise the query will be slow and a COUNT(*) is better.

In CI3 I could inject the SELECT directly into the $db object, but that's not the case in CI4 where the $db is not global. Rather than passing around $db I wonder if it is possible to extend \CodeIgniter\Database\MySQLi\Builder with my own function to add a function so I could do something like this:
PHP Code:
$query $builder
    
->calc_found_rows()                // Should check for filter in the request and SQL_CALC_FOUND_ROWS
    
->select('userID,firstname,lastname,email')
    ->
add_request_filters()            // Another function I'd like to add
    
->get($this->limit$this->start); // Paging parameters set in the extended Controller
        
    
$total $builder->get_total_count(); // If SQL_CALC_FOUND_ROWS used, get FOUND_ROWS() else COUNT(*) 

I have tried adding a class Builder.php to app/Database/MySQLi extending \CodeIgniter\Database\MySQLi\Builder but it doesn't load.

I know that I can hack the class in system but that sort of defeats the purpose of having composer-supported frameworks.

Thanks,
/Mattias
Reply


Messages In This Thread
Extending \CodeIgniter\Database\MySQLi\Builder possible? - by tgix - 08-10-2019, 01:42 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.