-- name: CreateDistrict :one
INSERT INTO districts (
    name,
    code
 ) VALUES (
    $1, $2
 ) RETURNING *;

-- name: GetDistrict :one
SELECT * FROM districts
WHERE id = $1 LIMIT 1;

-- name: GetDistrictIdByName :one
SELECT id FROM districts
WHERE name = $1 LIMIT 1;

-- name: GetDistrictByName :one
SELECT * FROM districts
WHERE name = $1 LIMIT 1;

-- name: ListDistricts :many
SELECT * from districts
ORDER BY id LIMIT $1
OFFSET $2;

-- name: AllDistricts :many
SELECT * FROM districts;

-- name: UpdateDistrict :one
UPDATE districts
  set 
    name = $2,
    code = $3
WHERE id = $1
RETURNING *;

-- name: DeleteDisrict :exec
DELETE FROM districts WHERE id= $1;

-- name: GetDistrictIDByCode :one
SELECT id from districts WHERE 
code= $1 LIMIT 1;