Create query for find citizen By Username

This commit is contained in:
2019-08-27 11:16:35 +02:00
parent 2c717609b1
commit 67665350eb
2 changed files with 24 additions and 0 deletions

View File

@@ -24,6 +24,12 @@ class Citizen(override var requester: Requester) : RepositoryI<CitizenEntity> {
.selectOne("user_id" to user.id)
}
fun findByUsername(unsername: String): CitizenEntity? {
return requester
.getFunction("find_citizen_by_username")
.selectOne("username" to unsername)
}
fun find(
page: Int = 1,
limit: Int = 50,

View File

@@ -0,0 +1,18 @@
create or replace function find_citizen_by_username(username text, out resource json) language plpgsql as
$$
declare
_username alias for username;
begin
select to_json(t) into resource
from (
select
z.*,
find_user_by_id(u.id) as "user"
from citizen as z
join "user" as u on z.user_id = u.id
where u.username = _username
) as t;
end;
$$;
-- drop function if exists find_citizen_by_username(text, out json);