SQLite

SQLite Query Structure

When using SQLite as a datasource in Jigx, queries are written in an idiomatic SQL pattern, selecting the id and data columns from Jigx tables (e.g., [default/customers]), applying joins with related tables (e.g., [default/orders]), filtering with json_extract expressions on the data JSON payload, supporting parameters like @search or @status, and finishing with standard clauses such as ORDER BY and LIMIT for predictable, efficient results.

SQLite datasource
SELECT
  id,
  data
FROM [default/customers] AS cus
INNER JOIN [default/orders] AS ord
  ON ord.customer_id = cus.id
WHERE (
    @search IS NULL OR @search = '' 
    OR json_extract(cus.data, '$.name') LIKE '%' || @search || '%'
    OR json_extract(cus.data, '$.email') LIKE '%' || @search || '%'
  )
  AND json_extract(cus.data, '$.active') = 1
  AND json_extract(ord.data, '$.status') = @status
ORDER BY
  json_extract(cus.data, '$.lastName'),
  json_extract(cus.data, '$.firstName')
LIMIT 100

Key Elements:

Element
Description

[default/table]

FQN bracket notation (fully qualified name)

AS cus

Table aliases (3-letter preferred)

json_extract(data, '$.prop')

JSON property access

@search, @status

Query parameters for filtering

LIKE '%' || @param || '%'

Parameter concatenation for search

@param IS NULL OR @param = ''

Null/empty parameter handling

SELECT id, data

Standard column pattern

UPPERCASE

SQL keywords always uppercase

Common Variations

Basic List

Singleton

Aggregation

Use .isDocument(true) to avoid @ctx.datasources.stats[0]

JSON Property Access

Shred (Special cases only)

This works fine but becomes hard to maintain with many properties eg passing 10 fields to a form.

CTEs

Compose complexity via CTEs for clarity/maintainability.

SDK Integration

Quick Patterns

Considerations

  • Use the following in SQLite queries:

    • Always use FQN bracket notation: [default/table]

    • All keywords UPPERCASE: SELECT, FROM, WHERE

    • json_extract()

    • Use table aliases for clarity: AS cus, AS ord

    • Use @params for filters

    • Parameters start with @: @search, @customerId

    • Standard pattern: SELECT id, data with .jsonProperties('data')

    • Single records use .isDocument(true)

  • Avoid using the following in SQLite queries:

    • Lowercase keywords

    • Field extraction

    • Unqualified tables

    • direct column access

See sqlite for examples of SQLite datasources used in Jigx.

Last updated

Was this helpful?