Skip to content

Allow SQL in widget configuration #233

@timwis

Description

@timwis

Rather than trying to stuff it into rarely-used config options like aggregateFunction and valueField, we could just allow an "advanced" option/escape hatch, where you literally pass SQL. This would of course have to be limited to the Carto provider as services like Socrata, CKAN, DKAN don't support SQL queries (as far as I know).

The tricky part is injecting the global filters into the user's SQL string. A couple options so far:

  1. Pass the filter object, with a method to convert it to a WHERE clause, to the SQL configuration "callback", e.g.:
{
  "title": "Crime incidents",
  ...
  "sql": function (filters) {
    // filtersObj is the AST, in case you need to manipulate it
    return `select * from foo where 1 and ${filters.toString()}`
  }
}
  1. Use the user's SQL as a nested query (select * from (select from ...) where <global filters>)

The 2nd option probably makes more sense if we only need it for carto, but the 1st option is more likely to fit into other providers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions