Usage of global datasource with query parameter

When building the demos, I often find myself in a situation where i need to use datasource multiple times in different jigs. In order to prevent using datasource in each jig, it’s better to use datasource as a global one that will be accessible from any jig in the solution.

Global datasource has to be created in datasources folder. This datasource can use either DYNAMIC provider or LOCAL provider. The only limitation of the global datasource is the usage of query parameter. Because in different jigs, you want to use same datasource but for example with different query parameters.
We can deal with this limitation with the code bellow. We are going to create simple global datasource that will select all people in the company.

datasource:

type: datasource.sqlite
options:
  provider: DATA_PROVIDER_LOCAL

  entities:
    - entity: people

  query: SELECT id, '$.first_name', '$.last_name','$.department'  from [people]

Now we want to use this global datasource in a jig, where we will create a simple list with people that are from department IT:

title: My people
type: jig.list

header:
  type: component.jig-header
  options:
    height: small
    children: 
      type: component.image
      options:
        source:
          uri: https://images.unsplash.com/photo-1674574124345-02c525664b65?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80

data: =@ctx.datasources.people[department = 'IT']
item: 
  type: component.list-item
    title: =@ctx.current.item.first_name 
    subtitle: =@ctx.current.item.first_name 

See that in this example we have added the query brackets after the datasource name, in order to filter people by department, similar we can do this with different query parameters in these brackets.