Create query for find citizen By Username
This commit is contained in:
@@ -24,6 +24,12 @@ class Citizen(override var requester: Requester) : RepositoryI<CitizenEntity> {
|
|||||||
.selectOne("user_id" to user.id)
|
.selectOne("user_id" to user.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun findByUsername(unsername: String): CitizenEntity? {
|
||||||
|
return requester
|
||||||
|
.getFunction("find_citizen_by_username")
|
||||||
|
.selectOne("username" to unsername)
|
||||||
|
}
|
||||||
|
|
||||||
fun find(
|
fun find(
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
limit: Int = 50,
|
limit: Int = 50,
|
||||||
|
|||||||
@@ -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);
|
||||||
Reference in New Issue
Block a user