improve Query Builder to make more complex queries |
I suggest query builder should have some options:
1 - easy to make a sub query today i used...: $this->db->select('field'); $this->db->from('table') $this->db->where('field', 'sub select here make in hand ... e.g select field from outher table where outher field= field') I suggest.. $dbObject = $this->db->select('field')->from('table')->where(''); $this->db->select('field)->from('table')->where('field', $dbObject); 2 - easy to make a union $dbObject1 = $this->db->select('field')->from('table')->where(''); $dbObject2 = $this->db->select('field')->from('table')->where(''); $this->db->select()->union($dbObject1, $dbObject2); (10-14-2016, 06:25 AM)andersonunsonst Wrote: I suggest query builder should have some options: For sub-queries, I believe Query Grouping already handles that, even in CI. That aside, I don't understand how this example would work. You're comparing a field with a partially generated query. How would it know what you're expecting to compare it to? (10-14-2016, 06:25 AM)andersonunsonst Wrote: 2 - easy to make a union You're correct that it doesn't currently have unions. To be honest, I've never used a union in the last 10 years, but I'm probably missing out. Before we could think to do that, we'd need to see how it would compare across all of the databases we support. If that works out, then perhaps. I'd wouldn't mind seeing a pull request for changes to support this, with tests, of course. (10-16-2016, 08:20 PM)kilishan Wrote: For sub-queries, I believe Query Grouping already handles that, even in CI. That aside, I don't understand how this example would work. You're comparing a field with a partially generated query. How would it know what you're expecting to compare it to? Grouping queries looks ugly. I want to suggest using an anonymous function. PHP Code: $builder->where(function(BaseBuilder $builder) { Subqueries? PHP Code: $builder->where('key', function(BaseBuilder $builder) { it's easy (05-10-2019, 12:54 AM)iRedds Wrote:(10-16-2016, 08:20 PM)kilishan Wrote: For sub-queries, I believe Query Grouping already handles that, even in CI. That aside, I don't understand how this example would work. You're comparing a field with a partially generated query. How would it know what you're expecting to compare it to? You show submit a PR of the uploaded file, it would be easy to review.
Looks like someone has submitted a PR for this that I'll review shortly.
I'm late to this party but this looks like an enticing feature. I use subqueries quite a bit in non-framework contexts, so it would be nice to have a transparent way to do that in CI4 as well.
|
Welcome Guest, Not a member yet? Register Sign In |