[coldbox-any] QueryBuilder Support

I need some query builder support. Bought and watched the 2019 in the box presentation with Andrew and want to implement but having some trouble with the “magic” of how the utility gets the “default” datasource so I don’t have to pass anything on every call…but I can’t find any direct line or dedicated blog space or google group to get help. Anyone know how I can get some support on this tooling ?


this.defaultdatasource=“yourdatasource” in application.cfc

Assuming that the string value is the coldfusion dsn name, no that does not work. I still get Attribute validation error for function executeQuery from the BaseGrammer.cfc in the qb models/grammar path. And in Coldbox, the dsn is defined in coldbox settings and injectable, and I’m like to have a more than just one datasource, so that solution kind of would not work well…I’m assuming there is a more appropriate path somewhere to give those datasource configuration settings from coldbox TO querybuilder.

When I inject the dsn (coldbox:setting:testdb for example) into my class, I create the querybuilder instance and query and then when I do go() or insert() or update() for testing, I pass options={datasource = dsn.name} and that works fine…I just don’t want to have to do that with every query I write…not to mention in all the demos and samples, no one else seems to do this…so I’m sure we are on the right track…I just could not get your suggestion to work.

Also, I searched the code for that variable name use and don’t find it anywhere. Hopefully I’m not overlooking the obvious.

Ah…so it’s actually this.datasource and yes that does seem to work. The rest of my concerns are still valid but at least I can see it working now using your recommendation.

Here’s the bit in the docs you are looking for: Query Options - qb

Using WireBox you can create pre-configured QueryBuilder instances. You can then inject those instances in your app to avoid having to pass the settings around all the time.

this.defaultdatasource is a lucee thing. Maybe you’re on ACF? I should have asked.


yeah…acf…I found that too…so you definitely were not wrong. As you can see now, Eric piped in with a solution…basically “cheat”, map my own “core” version that I can inject as needed.

However, Eric…since settings can be made in ColdBox to globally provide inject-able data source references…could there be a way on instantiation to automatically pull that by default as well as have a property that could override that when needed (or even just continue using the options {} parameter? or am I the only one that thinks that would be helpful?

Thank you both for your insights.

One last thing Eric…is the the best place to get that support for QB? i’m sure to have some nasty queries down the road…is there perhaps a slack channel I can subscribe to or a google group dedicated for this support and I’ll likely have some pull requests at some point too as this kind of technology is very near and dear to my heart…but I’m tired of rolling my own :slight_smile:


It’s not really a cheat - it’s the recommended way. As for ColdBox providing datasource references, that was deprecated in v5, so there is no plans to look at any of that configuration.

As far as support goes, here is fine. So is the CFML Slack or Box Team Slack. If you need more timely on in-depth help, you can also purchase support from Ortus and have a member of team Ortus (even myself!) help you out: Support & Consulting

“cheat” may have been a strong choice of words but only because I just think the other way is a bit more about convention and just prefer it personally. But knowing it was tried and some consensus was achieved that said it was a bad idea, I’ll acquiesce gratefully. Thanks for the help and direction for further support.