diff --git a/system/db/query.php b/system/db/query.php index 3e28f20d..0d053554 100644 --- a/system/db/query.php +++ b/system/db/query.php @@ -500,6 +500,20 @@ class Query { */ public function __call($method, $parameters) { + // --------------------------------------------------------- + // Dynamic methods allows the building of very expressive + // queries. All dynamic methods start with "where_". + // + // Ex: DB::table('users')->where_email($email)->first(); + // --------------------------------------------------------- + if (strpos($method, 'where_') === 0) + { + return Query\Dynamic::build($method, $parameters, $this); + } + + // --------------------------------------------------------- + // Handle any of the aggregate functions. + // --------------------------------------------------------- if (in_array($method, array('count', 'min', 'max', 'avg', 'sum'))) { return ($method == 'count') ? $this->aggregate(Str::upper($method), '*') : $this->aggregate(Str::upper($method), $parameters[0]); diff --git a/system/db/query/dynamic.php b/system/db/query/dynamic.php new file mode 100644 index 00000000..ea90e2ea --- /dev/null +++ b/system/db/query/dynamic.php @@ -0,0 +1,60 @@ +where($segment, '=', $parameters[$index], $connector); + + $index++; + } + else + { + $connector = trim(Str::upper($segment), '_'); + } + } + + return $query; + } + +} \ No newline at end of file