From 1f647374a8cdf3bc5c2d29ff8be277b027925c8c Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sat, 30 Mar 2024 16:36:54 -0400 Subject: post comments, refactor post loading, hide load more btn --- db/rest/util/_api_trim.sql | 25 +++++++++++++++++++++++++ db/rest/util/_api_validate_text.sql | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 db/rest/util/_api_trim.sql (limited to 'db/rest/util') diff --git a/db/rest/util/_api_trim.sql b/db/rest/util/_api_trim.sql new file mode 100644 index 0000000..c972282 --- /dev/null +++ b/db/rest/util/_api_trim.sql @@ -0,0 +1,25 @@ +CREATE FUNCTION _api.trim( + _text TEXT +) +RETURNS TEXT +LANGUAGE plpgsql VOLATILE +AS $BODY$ +DECLARE + _new TEXT; +BEGIN + + IF _text IS NULL THEN + RETURN NULL; + END IF; + + _new = _text; + _new = TRIM(_new); + _new = REGEXP_REPLACE(_new, '^(?: |\r|\n)*', ''); + _new = REGEXP_REPLACE(_new, '(?: |\r|\n)*$', ''); + + RETURN _new; +END +$BODY$; + +GRANT EXECUTE ON FUNCTION _api.trim(TEXT) + TO rest_anon, rest_user; diff --git a/db/rest/util/_api_validate_text.sql b/db/rest/util/_api_validate_text.sql index e4a6a7b..ff3a227 100644 --- a/db/rest/util/_api_validate_text.sql +++ b/db/rest/util/_api_validate_text.sql @@ -33,6 +33,7 @@ BEGIN _detail => _column, _hint => _min || '' ); + RETURN FALSE; END IF; IF _max IS NOT NULL AND _length > _max THEN @@ -41,6 +42,7 @@ BEGIN _detail => _column, _hint => _max || '' ); + RETURN FALSE; END IF; RETURN TRUE; -- cgit v1.2.3-freya