2016-08-24 22:46:29 +00:00
|
|
|
-- Users ---------------------------------------------------------------------------
|
|
|
|
|
2016-08-20 21:36:09 +00:00
|
|
|
-- :name create-user! :! :n
|
|
|
|
-- :doc creates a new user record
|
|
|
|
INSERT INTO users
|
2016-08-22 00:22:39 +00:00
|
|
|
(id, login, name, email, token, address, created)
|
|
|
|
VALUES (:id, :login, :name, :email, :token, :address, :created);
|
2016-08-20 21:36:09 +00:00
|
|
|
|
|
|
|
-- :name update-user! :! :n
|
2016-08-24 22:46:29 +00:00
|
|
|
-- :doc updates an existing user record
|
2016-08-20 21:36:09 +00:00
|
|
|
UPDATE users
|
2016-08-22 00:22:39 +00:00
|
|
|
SET login = :login, name = :name, email = :email, token = :token, address = :address
|
|
|
|
WHERE id = :id;
|
|
|
|
|
2016-08-24 22:46:29 +00:00
|
|
|
-- :name update-user-token! :<! :1
|
|
|
|
-- :doc updates user token and returns updated user
|
|
|
|
UPDATE users
|
|
|
|
SET token = :token
|
|
|
|
WHERE login = :login
|
|
|
|
RETURNING id, login, name, email, token, address, created;
|
|
|
|
|
2016-08-22 00:22:39 +00:00
|
|
|
-- :name update-user-address! :! :n
|
|
|
|
UPDATE users
|
|
|
|
SET address = :address
|
2016-08-22 23:27:49 +00:00
|
|
|
WHERE login = :login;
|
2016-08-20 21:36:09 +00:00
|
|
|
|
|
|
|
-- :name get-user :? :1
|
2016-08-22 00:22:39 +00:00
|
|
|
-- :doc retrieve a user given the login.
|
|
|
|
SELECT *
|
|
|
|
FROM users
|
|
|
|
WHERE login = :login;
|
2016-08-20 21:36:09 +00:00
|
|
|
|
2016-08-24 22:46:29 +00:00
|
|
|
-- Repositories --------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- :name toggle-repository! :<! :1
|
|
|
|
-- :doc toggles 'enabled' flag of a given repository
|
|
|
|
UPDATE repositories
|
|
|
|
SET enabled = NOT enabled
|
|
|
|
WHERE repo_id = :repo_id
|
|
|
|
RETURNING repo_id, login, repo, enabled;
|
|
|
|
|
|
|
|
-- :name create-repository! :<! :1
|
|
|
|
-- :doc creates repository if not exists
|
|
|
|
INSERT INTO repositories (repo_id, login, repo, enabled)
|
|
|
|
SELECT
|
|
|
|
:repo_id,
|
|
|
|
:login,
|
|
|
|
:repo,
|
|
|
|
:enabled
|
|
|
|
WHERE NOT exists(SELECT 1
|
|
|
|
FROM repositories
|
|
|
|
WHERE repo_id = :repo_id)
|
|
|
|
RETURNING repo_id, login, repo, enabled;
|
|
|
|
|
|
|
|
-- :name get-enabled-repositories :? :*
|
|
|
|
-- :doc returns enabled repositories for a given login
|
|
|
|
SELECT repo_id
|
|
|
|
FROM repositories
|
|
|
|
WHERE login = :login AND enabled = TRUE
|