Загрузка функций и проекта "Нарушениям нет"
This commit is contained in:
42
Database/Функции/application_get.sql
Normal file
42
Database/Функции/application_get.sql
Normal file
@@ -0,0 +1,42 @@
|
||||
CREATE OR REPLACE FUNCTION nn_db.application_get(
|
||||
in_pk_user nn_db.user.pk_user%TYPE)
|
||||
RETURNS TABLE(
|
||||
pk_application nn_db.application.pk_application%TYPE
|
||||
, car_number nn_db.application.car_number%TYPE
|
||||
, description nn_db.application.description%TYPE
|
||||
, fk_status nn_db.application.fk_status%TYPE
|
||||
, title nn_db.status.title%TYPE
|
||||
, fk_user nn_db.application.fk_user%TYPE
|
||||
, username nn_db.user.username%TYPE
|
||||
, pk_image nn_db.image.pk_image%TYPE
|
||||
, file_name nn_db.image.file_name%TYPE
|
||||
, file_ext nn_db.image.file_ext%TYPE)
|
||||
AS $$
|
||||
BEGIN
|
||||
RETURN QUERY SELECT
|
||||
nn_db.application.pk_application
|
||||
, nn_db.application.car_number
|
||||
, nn_db.application.description
|
||||
, nn_db.application.fk_status
|
||||
, nn_db.status.title
|
||||
, nn_db.application.fk_user
|
||||
, nn_db.user.username
|
||||
, nn_db.image.pk_image
|
||||
, nn_db.image.file_name
|
||||
, nn_db.image.file_ext
|
||||
FROM nn_db.application
|
||||
INNER JOIN nn_db.status
|
||||
ON nn_db.status.pk_status = nn_db.application.fk_status
|
||||
INNER JOIN nn_db.user
|
||||
ON nn_db.user.pk_user = nn_db.application.fk_user
|
||||
LEFT JOIN nn_db.image
|
||||
ON nn_db.image.fk_application = nn_db.application.pk_application
|
||||
WHERE
|
||||
CASE WHEN in_pk_user IS NULL
|
||||
THEN nn_db.application.fk_user IN (SELECT nn_db.user.pk_user FROM nn_db.user)
|
||||
ELSE
|
||||
nn_db.application.fk_user = in_pk_user
|
||||
END
|
||||
ORDER BY nn_db.application.pk_application;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql
|
||||
19
Database/Функции/application_patch.sql
Normal file
19
Database/Функции/application_patch.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
CREATE OR REPLACE FUNCTION nn_db.application_patch(
|
||||
in_pk_application nn_db.application.pk_application%TYPE
|
||||
, in_fk_status nn_db.application.fk_status%TYPE)
|
||||
RETURNS TABLE(confirm boolean)
|
||||
AS $$
|
||||
BEGIN
|
||||
UPDATE nn_db.application
|
||||
SET nn_db.application.fk_status = in_fk_status
|
||||
WHERE
|
||||
nn_db.application.pk_application = in_pk_application;
|
||||
|
||||
RETURN QUERY SELECT (
|
||||
CASE WHEN
|
||||
(SELECT fk_status FROM nn_db.application WHERE pk_application = in_pk_application LIMIT 1) = in_fk_status
|
||||
THEN True
|
||||
ELSE False
|
||||
END);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql
|
||||
22
Database/Функции/application_post.sql
Normal file
22
Database/Функции/application_post.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
CREATE OR REPLACE FUNCTION nn_db.application_post(
|
||||
in_car_number nn_db.application.car_number%TYPE
|
||||
, in_description nn_db.application.description%TYPE
|
||||
, in_fk_user nn_db.application.fk_user%TYPE)
|
||||
RETURNS TABLE(pk_application nn_db.application.pk_application%TYPE)
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO nn_db.application (
|
||||
car_number
|
||||
, description
|
||||
, fk_status
|
||||
, fk_user)
|
||||
VALUES (
|
||||
in_car_number
|
||||
, in_description
|
||||
, (SELECT MIN(nn_db.status.pk_status) FROM nn_db.status)
|
||||
, in_fk_user);
|
||||
RETURN QUERY SELECT
|
||||
MAX(nn_db.application.pk_application)
|
||||
FROM nn_db.application;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
12
Database/Функции/image_post.sql
Normal file
12
Database/Функции/image_post.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
CREATE OR REPLACE FUNCTION nn_db.image_post(
|
||||
in_file_name nn_db.image.file_name%TYPE
|
||||
, in_file_ext nn_db.image.file_ext%TYPE
|
||||
, in_fk_application nn_db.image.fk_application%TYPE)
|
||||
RETURNS TABLE(pk_image nn_db.image.pk_image%TYPE)
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO nn_db.image (file_name, file_ext, fk_application)
|
||||
VALUES (in_file_name, in_file_ext, in_fk_application);
|
||||
RETURN QUERY SELECT MAX(nn_db.image.pk_image) FROM nn_db.image;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql
|
||||
12
Database/Функции/status_get.sql
Normal file
12
Database/Функции/status_get.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
CREATE OR REPLACE FUNCTION nn_db.status_get()
|
||||
RETURNS TABLE(
|
||||
pk_status nn_db.status.pk_status%TYPE
|
||||
, title nn_db.status.title%TYPE)
|
||||
AS $$
|
||||
BEGIN
|
||||
RETURN QUERY SELECT
|
||||
nn_db.status.pk_status, nn_db.status.title
|
||||
FROM nn_db.status
|
||||
ORDER BY nn_db.status.pk_status;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql
|
||||
11
Database/Функции/status_post.sql
Normal file
11
Database/Функции/status_post.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE OR REPLACE FUNCTION nn_db.status_post(
|
||||
in_title nn_db.status.title%TYPE)
|
||||
RETURNS TABLE(pk_status nn_db.status.pk_status%TYPE)
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO nn_db.status (title)
|
||||
VALUES (in_title);
|
||||
|
||||
RETURN QUERY SELECT MAX(nn_db.status.pk_status) FROM nn_db.status;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql
|
||||
16
Database/Функции/user_activate.sql
Normal file
16
Database/Функции/user_activate.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
CREATE OR REPLACE FUNCTION nn_db.user_activate(
|
||||
in_pk_user nn_db.user.pk_user%TYPE)
|
||||
RETURNS TABLE(confirm boolean)
|
||||
AS $$
|
||||
BEGIN
|
||||
UPDATE nn_db.user
|
||||
SET is_active = True
|
||||
WHERE
|
||||
pk_user = in_pk_user;
|
||||
RETURN QUERY SELECT
|
||||
is_active = True
|
||||
FROM nn_db.user
|
||||
WHERE
|
||||
nn_db.user.pk_user = in_pk_user;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql
|
||||
32
Database/Функции/user_get.sql
Normal file
32
Database/Функции/user_get.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
CREATE OR REPLACE FUNCTION nn_db.user_get(
|
||||
in_search_value nn_db.user.username%TYPE)
|
||||
RETURNS TABLE(
|
||||
pk_user nn_db.user.pk_user%TYPE
|
||||
, lastname nn_db.user.lastname%TYPE
|
||||
, firstname nn_db.user.firstname%TYPE
|
||||
, middlename nn_db.user.middlename%TYPE
|
||||
, username nn_db.user.username%TYPE
|
||||
, password_hash nn_db.user.password_hash%TYPE
|
||||
, email nn_db.user.email%TYPE
|
||||
, phone nn_db.user.phone%TYPE
|
||||
, is_admin nn_db.user.is_admin%TYPE
|
||||
, is_active nn_db.user.is_active%TYPE)
|
||||
AS $$
|
||||
BEGIN
|
||||
RETURN QUERY SELECT
|
||||
nn_db.user.pk_user
|
||||
, nn_db.user.lastname
|
||||
, nn_db.user.firstname
|
||||
, nn_db.user.middlename
|
||||
, nn_db.user.username
|
||||
, nn_db.user.password_hash
|
||||
, nn_db.user.email
|
||||
, nn_db.user.phone
|
||||
, nn_db.user.is_admin
|
||||
, nn_db.user.is_active
|
||||
FROM nn_db.user
|
||||
WHERE
|
||||
nn_db.user.username ILIKE in_search_value
|
||||
OR nn_db.user.email ILIKE in_search_value;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql
|
||||
35
Database/Функции/user_post.sql
Normal file
35
Database/Функции/user_post.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
CREATE OR REPLACE FUNCTION nn_db.user_post(
|
||||
in_lastname nn_db.user.lastname%TYPE
|
||||
, in_firstname nn_db.user.firstname%TYPE
|
||||
, in_middlename nn_db.user.middlename%TYPE
|
||||
, in_username nn_db.user.username%TYPE
|
||||
, in_password_hash nn_db.user.password_hash%TYPE
|
||||
, in_email nn_db.user.email%TYPE
|
||||
, in_phone nn_db.user.phone%TYPE)
|
||||
RETURNS TABLE(pk_user nn_db.user.pk_user%TYPE)
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO nn_db.user(
|
||||
lastname
|
||||
, firstname
|
||||
, middlename
|
||||
, username
|
||||
, password_hash
|
||||
, email
|
||||
, phone
|
||||
, is_admin
|
||||
, is_active)
|
||||
VALUES(
|
||||
in_lastname
|
||||
, in_firstname
|
||||
, in_middlename
|
||||
, in_username
|
||||
, in_password_hash
|
||||
, in_email
|
||||
, in_phone
|
||||
, False
|
||||
, False);
|
||||
|
||||
RETURN QUERY SELECT MAX(nn_db.user.pk_user) FROM nn_db.user;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql
|
||||
Reference in New Issue
Block a user