-- name: GetUserByNickname :one
SELECT *
FROM users
WHERE nickname = sqlc.arg('nickname');

-- name: CreateNewUser :one
INSERT 
INTO users (passhash, nickname) 
VALUES (sqlc.arg(passhash), sqlc.arg(nickname))
RETURNING id;

-- name: GetExternalServiceByToken :one
SELECT *
FROM external_services
WHERE auth_token = sqlc.arg('auth_token');

-- name: GetUserByExternalServiceId :one
SELECT u.*
FROM users u
LEFT JOIN external_ids ei ON eu.user_id = u.id
WHERE ei.external_id = sqlc.arg('external_id') AND ei.service_id = sqlc.arg('service_id');