-- name: CreateExitHandler :one
INSERT INTO exithandlers (
    exhcode,                                
    exhdescription,
    exitpoint
 ) VALUES (
    $1, $2, $3
 ) RETURNING *;

-- name: GetExitHandler :one
SELECT * FROM exithandlers
WHERE id = $1 LIMIT 1;

-- name: ListExitHanlders :many
SELECT * FROM exithandlers
ORDER BY id LIMIT $1
OFFSET $2;

-- name: AllExitHandlers :many
SELECT exithandlers.id as exithandler_id, exhcode,exhdescription,exitpoints.expdescription,exitpoints.expcode,village,parish,districts.name FROM exithandlers
JOIN   exitpoints on exitpoints.id = exithandlers.exitpoint
JOIN   villages  on villages.id    = exitpoints.village_id
JOIN   parishes  on parishes.id    = exitpoints.parish_id
JOIN   districts on districts.id   = exitpoints.district_id
ORDER BY exithandlers.id;


-- name: UpdateExitHandler :one
UPDATE exithandlers
  set 
     exhcode = $2,                                
     exhdescription = $3,
     exitpoint = $4
WHERE id = $1
RETURNING *;

-- name: DeleteExitHandler :exec
DELETE FROM exithandlers WHERE id= $1;