How to use query editor in custom module?

I’m trying to extend paged query to allow user to filter on multiple columns in table.

I extended paged query and I’m looking for the hjson of the Wappler paged query to stick as much as possible as the original, but I can’t find if it’s possible to have the query editor as the original database query modules.

EDIT: For the dropdown of database connections I don’t know if we can have that too in custom modules?

From what we know, query editor is not available for use in the Custom Module capabilities.

1 Like

I’ve seen Paged custom query this post and maybe @JonL have something to share? Or I go along with just a text field, I don’t know

So what’s the issue to filter a paged query by multiple columns right now, using the query builder?

Maybe I’ve missed some option but I don’t currently see how I can in a paged query filter from dynamic column with dynamic “search value”.

Example for url would be:

/api/request?sort=a&dir=asc&filter=b|testORa|3

And my request would generate a where clause like:

SELECT ... WHERE b ~'test' OR a > 3

Something like that (don’t have the final design if you have suggestion :slight_smile: The idea is to allow user to click on a column and filter by dropdown when column type is an enum, if the type is date allow them to select a range of months or year, etc)

So is this now what you want?

Well yes but I want the name of the column and the number of filter be dynamic, coming from the request and then I do something like that (from last example):

$_GET
  .filter
  .split('OR')
  .forEach(or => addWhereOrInRequest(or.split('|')))

No, that is not supported.
You can just define the columns and their filters and toggle the filters conditionally.

Yeah I’d figured that out and move to custom modules

You can just add all columns you want to filter and add a conditional per column when to activate the filter. So you will have multiple conditional activated filters like this.

1 Like

Thank you so much it also “fix” another issue I had: duplicating queries to conditional where, never noticed this option, Awesome! :smiley:

1 Like

The conditional option in Query Builder is a great feature; QB would far less powerful/useful without it. Eg you can create pages with mulltiple search options with it.

As far as I know, the only way to create a completely dynamic query it to use a custom query to execute a stored procedure - eg you could store any query in a variable and run that.

1 Like

If you need full control over the query I don’t see another way but to use a custom module. My use case was very specific though as I wanted to pass the name of the table dynamically which is currently not possible with Wappler. Knex does a good job at making sure there is no SQL injection so I used knex for this.

1 Like

Do wappler use knex? I mean I’ve never wondered but now you say that I’m wondering if Wappler handle for me sql injection when I’m using Wappler modules?

For nodejs it does(in some components). Don’t know if they use it 100% throughout the app.

1 Like