-- name: CreateAirline :one
INSERT INTO airlines (
    airlinecode,
    airlinename,
    modeoftransport_id
 ) VALUES (
    $1, $2, $3
 ) RETURNING *;

-- name: GetAirline :one
SELECT * FROM airlines
WHERE id = $1 LIMIT 1;

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

-- name: AllAirlines :many
SELECT airlines.id as airline_id,airlines.airlinecode,airlines.airlinename,modeoftransport_id mot_id,
motdescription,airlines.created_at created_at FROM airlines
JOIN modesoftransport on modesoftransport.id = airlines.modeoftransport_id;

-- name: AllListedAirlines :many
SELECT airlinecode,airlinename,airlines.id,modeoftransport_id mot_id,motdescription,airlines.created_at created_at FROM airlines
JOIN modesoftransport on modesoftransport.id = airlines.modeoftransport_id;

-- name: UpdateAirline :one
UPDATE airlines
  set 
    airlinecode = $2,
    airlinename = $3,
    modeoftransport_id = $4
WHERE id = $1
RETURNING *;

-- name: DeleteAirline :exec
DELETE FROM airlines WHERE id= $1;