From adc2fda90a3b8308e8a9df202d5ec418a9220ff8 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Mon, 29 Apr 2024 08:17:12 +0000 Subject: [PATCH] feat: store last select columns in property (#40) --- src/MySQL.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/MySQL.php b/src/MySQL.php index 7147636..cf7e9ef 100644 --- a/src/MySQL.php +++ b/src/MySQL.php @@ -17,10 +17,13 @@ private string $table; private ?array $model = null; - private ?string $order_by = null; - private ?string $filter_sql = null; - private array $filter_values = []; private ?string $limit = null; + private ?string $order_by = null; + private array $filter_values = []; + private ?string $filter_sql = null; + + // Array of last SELECT-ed columns + public ?array $columns = null; // Pass constructor arguments to driver function __construct() { @@ -225,15 +228,15 @@ $this->throw_if_no_table(); // Create array of columns from CSV - $columns = is_array($columns) || is_null($columns) ? $columns : explode(",", $columns); + $this->columns = is_array($columns) || is_null($columns) ? $columns : explode(",", $columns); // Filter columns that aren't in the model if defiend if ($columns && $this->model) { - $columns = $this->in_model($columns); + $columns = $this->in_model($this->columns); } // Create CSV from columns or default to SQL NULL as a string - $columns_sql = $columns ? implode(",", $columns) : "NULL"; + $columns_sql = $this->columns ? implode(",", $this->columns) : "NULL"; // Create LIMIT statement if argument is defined $limit_sql = !is_null($this->limit) ? " LIMIT {$this->limit}" : "";