enum for order in endpoints
That's general note to the endpoints supporting ordering: let's define an enum type specific to given endpoint order capabilities. The PostgreSQL type system should automatically take care for values matching (and throwing an error when specified value does not belong to given enum). Then we could simplify implementations and remove checks like this one in line #71 (closed) like also simplify ORDER BY clauses by supplementing all values in CASE
stmt selecting proper ordering, what effectively could allow to finally removed dynamic sql (executed under format
).
See: https://www.postgresql.org/docs/current/datatype-enum.html
IF _order_is IS NULL THEN
_order_is = 'desc';
END IF;
RETURN CASE WHEN arr IS NOT NULL THEN to_json(arr) ELSE '[]'::JSON END FROM (
SELECT ARRAY(
SELECT hafbe_backend.get_set_of_witness_voters_daily_change(__witness_id, _limit, _offset, _order_by, _order_is)
SELECT hafbe_backend.get_set_of_witness_votes_history(__witness_id, _order_by, _order_is, _limit, _from_time, _to_time)
) arr
) result;
END
$$
;
CREATE OR REPLACE FUNCTION hafbe_endpoints.get_witnesses(_limit INT = 1000, _offset INT = 0, _order_by TEXT = 'votes', _order_is TEXT = 'desc')
CREATE OR REPLACE FUNCTION hafbe_endpoints.get_witnesses(_limit INT = 100, _offset INT = 0, _order_by TEXT = 'votes', _order_is TEXT = 'desc')