Skip to content

Commit be27663

Browse files
authored
Bug Fix for Sorting (#41)
* fix bug with sort vs sortby
1 parent de26c36 commit be27663

File tree

7 files changed

+1634
-14
lines changed

7 files changed

+1634
-14
lines changed

pypgstac/pypgstac/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""PyPGStac Version."""
2-
__version__ = "0.3.0"
2+
__version__ = "0.3.1"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
SET SEARCH_PATH to pgstac, public;
2+
set check_function_bodies = off;
3+
4+
CREATE OR REPLACE FUNCTION pgstac.sort_sqlorderby(_search jsonb DEFAULT NULL::jsonb, reverse boolean DEFAULT false)
5+
RETURNS text
6+
LANGUAGE sql
7+
AS $function$
8+
WITH sorts AS (
9+
SELECT
10+
(items_path(value->>'field')).path as key,
11+
parse_sort_dir(value->>'direction', reverse) as dir
12+
FROM jsonb_array_elements(
13+
'[]'::jsonb
14+
||
15+
coalesce(_search->'sortby','[{"field":"datetime", "direction":"desc"}]')
16+
||
17+
'[{"field":"id","direction":"desc"}]'::jsonb
18+
)
19+
)
20+
SELECT array_to_string(
21+
array_agg(concat(key, ' ', dir)),
22+
', '
23+
) FROM sorts;
24+
$function$
25+
;
26+
27+
28+
29+
INSERT INTO migrations (version) VALUES ('0.3.1');

0 commit comments

Comments
 (0)