Skip to content

Commit

Permalink
Update to version 0.3.2 (#44)
Browse files Browse the repository at this point in the history
* Update version to 0.3.2

* Update CHANGELOG for 0.3.2

Let a TODO for previous versions without change entries
  • Loading branch information
lossyrob authored Aug 17, 2021
1 parent e3303e2 commit d1f4df4
Show file tree
Hide file tree
Showing 6 changed files with 1,673 additions and 8 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Changelog

## [Unreleased]
## [v0.3.2]

### Added
## Fixed

### Changed
- Fixed CQL term to be "collections", not "collection" ([#43](https://github.com/stac-utils/pgstac/pull/43))

### Removed
## [v0.3.1]

## Fixed
_TODO_

## [v0.2.8]

Expand Down
2 changes: 1 addition & 1 deletion pypgstac/pypgstac/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""PyPGStac Version."""
__version__ = "0.3.1"
__version__ = "0.3.2"
74 changes: 74 additions & 0 deletions pypgstac/pypgstac/migrations/pgstac.0.3.1-0.3.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
SET SEARCH_PATH to pgstac, public;
set check_function_bodies = off;

CREATE OR REPLACE FUNCTION pgstac.add_filters_to_cql(j jsonb)
RETURNS jsonb
LANGUAGE plpgsql
AS $function$
DECLARE
newprop jsonb;
newprops jsonb := '[]'::jsonb;
BEGIN
IF j ? 'id' THEN
newprop := jsonb_build_object(
'in',
jsonb_build_array(
'{"property":"id"}'::jsonb,
j->'id'
)
);
newprops := jsonb_insert(newprops, '{1}', newprop);
END IF;
IF j ? 'collections' THEN
newprop := jsonb_build_object(
'in',
jsonb_build_array(
'{"property":"collection"}'::jsonb,
j->'collections'
)
);
newprops := jsonb_insert(newprops, '{1}', newprop);
END IF;

IF j ? 'datetime' THEN
newprop := format(
'{"anyinteracts":[{"property":"datetime"}, %s]}',
j->'datetime'
);
newprops := jsonb_insert(newprops, '{1}', newprop);
END IF;

IF j ? 'bbox' THEN
newprop := format(
'{"intersects":[{"property":"geometry"}, %s]}',
j->'bbox'
);
newprops := jsonb_insert(newprops, '{1}', newprop);
END IF;

IF j ? 'intersects' THEN
newprop := format(
'{"intersects":[{"property":"geometry"}, %s]}',
j->'intersects'
);
newprops := jsonb_insert(newprops, '{1}', newprop);
END IF;

RAISE NOTICE 'newprops: %', newprops;

IF newprops IS NOT NULL AND jsonb_array_length(newprops) > 0 THEN
return jsonb_set(
j,
'{filter}',
cql_and_append(j, jsonb_build_object('and', newprops))
) - '{id,collections,datetime,bbox,intersects}'::text[];
END IF;

return j;
END;
$function$
;



INSERT INTO migrations (version) VALUES ('0.3.2');
Loading

0 comments on commit d1f4df4

Please sign in to comment.