Hi!
I've successfully set up basic server-side pagination - I'm trying to implement sorting and am stuck.
Scenario one:
WITH
cteCustomers AS (
SELECT
*
FROM
DEVELOPMENT_SCHEMA.CUSTOMERS
),
cteUnits AS (
SELECT
*
FROM
DEVELOPMENT_SCHEMA.UNITS
)
SELECT
e.ID,
c.CUSTOMER_NAME AS "Customer",
(
object_construct ('ID', u.UNIT_ID, 'NAME', u.UNIT_NAME)
) AS "Unit",
e.ENTRY_DATE AS "Operation Date",
e.UNIT_TARGET_ENTRY AS "Entry",
e.ADDED_BY_USER
FROM
DEVELOPMENT_SCHEMA.DAILY_DATA_ENTRY e
INNER JOIN cteCustomers c ON e.CUSTOMER_ID = c.CUSTOMER_ID
INNER JOIN cteUnits u ON e.UNIT_ID = u.UNIT_ID
ORDER BY
{{ DAILY_ENTRIES.sortArray[0]?.columnId || 'ENTRY_DATE' }} {{ DAILY_ENTRIES.sortArray[0]?.direction || 'DESC' }}
LIMIT
{{ DAILY_ENTRIES.pagination.pageSize }}
OFFSET
{{ DAILY_ENTRIES.pagination.offset || 0 }}
Here I get the following error: SQL compilation error: syntax error line 28 at position 6 unexpected '2'.
Scenario 2, based on some responses from the forums:
WITH
cteCustomers AS (
SELECT
*
FROM
CUSTOMERS
),
cteUnits AS (
SELECT
*
FROM
UNITS
)
SELECT
e.ID,
c.CUSTOMER_NAME AS "Customer",
(
object_construct ('ID', u.UNIT_ID, 'NAME', u.UNIT_NAME)
) AS "Unit",
e.ENTRY_DATE AS "Operation Date",
e.UNIT_TARGET_ENTRY AS "Entry",
e.ADDED_BY_USER
FROM
DAILY_DATA_ENTRY e
INNER JOIN cteCustomers c ON e.CUSTOMER_ID = c.CUSTOMER_ID
INNER JOIN cteUnits u ON e.UNIT_ID = u.UNIT_id
ORDER BY
CASE
WHEN {{ !DAILY_ENTRIES?.sortArray[0] }} THEN ENTRY_DATE
END DESC,
CASE
when {{ DAILY_ENTRIES?.sortArray[0]?.columnId == 'ENTRY_DATE' }}
AND {{ DAILY_ENTRIES?.sortArray[0]?.direction != 'asc'}} then ENTRY_DATE
end DESC,
CASE
when {{ DAILY_ENTRIES?.sortArray[0]?.columnId == 'ENTRY_DATE' }}
AND {{ DAILY_ENTRIES?.sortArray[0]?.direction == 'asc'}} then ENTRY_DATE
end ASC
LIMIT
{{ DAILY_ENTRIES.pagination?.pageSize }}
OFFSET
{{ DAILY_ENTRIES.pagination?.offset || 0 }}
This works but the query runs repeatedly in a loop.
Please help
UPDATE:
- I disabled converting queries to prepared sql statements and both queries 'worked'. Same behavior though. It appears that accessing the table's sortArray is what causes the query to run repeatedly.