Add pagination on query find_articles_versions_by_*
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
create or replace function find_articles_versions_by_id(in _id uuid, out resource json) language plpgsql as
|
||||
create or replace function find_articles_versions_by_id(
|
||||
_id uuid,
|
||||
"limit" int default 50,
|
||||
"offset" int default 0,
|
||||
out resource json,
|
||||
out total int
|
||||
) language plpgsql as
|
||||
$$
|
||||
declare
|
||||
_version_id uuid = (select version_id from article where id = _id);
|
||||
begin
|
||||
select find_articles_versions_by_version_id(_version_id)
|
||||
into resource;
|
||||
select a.resource, a.total
|
||||
into resource, total
|
||||
from find_articles_versions_by_version_id(_version_id, "limit", "offset") a;
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- drop function if exists find_articles_versions_by_id(uuid, out json);
|
||||
-- drop function if exists find_articles_versions_by_id(uuid, int, int, out json);
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
create or replace function find_articles_versions_by_version_id(in _version_id uuid, out resource json) language plpgsql as
|
||||
create or replace function find_articles_versions_by_version_id(
|
||||
_version_id uuid,
|
||||
"limit" int default 50,
|
||||
"offset" int default 0,
|
||||
out resource json,
|
||||
out total int
|
||||
) language plpgsql as
|
||||
$$
|
||||
begin
|
||||
select json_agg(t order by t.version_number desc)
|
||||
into resource
|
||||
select
|
||||
json_agg(t order by t.version_number desc),
|
||||
(select count(a) from article a where a.version_id = _version_id)
|
||||
into resource, total
|
||||
from (
|
||||
select
|
||||
a.*,
|
||||
@@ -10,8 +18,9 @@ begin
|
||||
from article as a
|
||||
where a.version_id = _version_id
|
||||
order by a.version_number desc
|
||||
limit "limit" offset "offset"
|
||||
) as t;
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- drop function if exists find_articles_versions_by_version_id(uuid, out json);
|
||||
-- drop function if exists find_articles_versions_by_version_id(uuid, int, int, out json);
|
||||
|
||||
Reference in New Issue
Block a user