edu-dis-labs-private/software/index.html

359 lines
95 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Реалізація інформаційного та програмного забезпечення | Xpertise</title>
<meta name="generator" content="VuePress 1.8.2">
<link rel="icon" href="/edu-dis-labs/favicon.ico">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<meta name="description" content="Лабораторні роботи з дисципліни "Організація баз даних"">
<link rel="preload" href="/edu-dis-labs/assets/css/0.styles.683d4db1.css" as="style"><link rel="preload" href="/edu-dis-labs/assets/js/app.dd23c768.js" as="script"><link rel="preload" href="/edu-dis-labs/assets/js/2.11435098.js" as="script"><link rel="preload" href="/edu-dis-labs/assets/js/24.92136d00.js" as="script"><link rel="prefetch" href="/edu-dis-labs/assets/js/10.e50a5206.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/11.29ee89f8.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/12.1a1e46b5.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/13.6b4a3ce8.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/14.2545c1ad.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/15.0aee5be2.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/16.13799d8c.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/17.058867d3.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/18.93992437.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/19.67a4f095.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/20.45f25853.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/21.c178c591.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/22.7414ef83.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/23.0457f9d4.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/25.1fc565c1.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/26.3b9f5f92.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/27.678360d8.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/28.01bbdb4a.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/3.3d08d86c.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/4.4c193c95.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/5.dea68fdd.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/6.6d8c3d51.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/7.9617083c.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/8.53a1b2bd.js"><link rel="prefetch" href="/edu-dis-labs/assets/js/9.1882ecda.js">
<link rel="stylesheet" href="/edu-dis-labs/assets/css/0.styles.683d4db1.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/edu-dis-labs/" class="home-link router-link-active"><!----> <span class="site-name">Xpertise</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/edu-dis-labs/" class="nav-link">
Початок
</a></div> <a href="http://139.162.162.130:3000/hasslesstech/edu-dis-labs" target="_blank" rel="noopener noreferrer" class="repo-link">
Gitea
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/edu-dis-labs/" class="nav-link">
Початок
</a></div> <a href="http://139.162.162.130:3000/hasslesstech/edu-dis-labs" target="_blank" rel="noopener noreferrer" class="repo-link">
Gitea
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <ul class="sidebar-links"><li><a href="/edu-dis-labs/intro/" class="sidebar-link">Вступ</a></li><li><section class="sidebar-group collapsable depth-0"><a href="/edu-dis-labs/requirements/" class="sidebar-heading clickable"><span>Розроблення вимог до системи</span> <span class="arrow right"></span></a> <!----></section></li><li><a href="/edu-dis-labs/use-cases/" class="sidebar-link">Розроблення вимог до функціональности системи</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/edu-dis-labs/use-cases/#загальна-схема" class="sidebar-link">Загальна схема</a></li><li class="sidebar-sub-header"><a href="/edu-dis-labs/use-cases/#схеми-використання-для-окремих-діячів" class="sidebar-link">Схеми використання для окремих діячів</a></li><li class="sidebar-sub-header"><a href="/edu-dis-labs/use-cases/#сценаріі-використання" class="sidebar-link">Сценарії використання</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/edu-dis-labs/use-cases/#для-гостя" class="sidebar-link">Для гостя</a></li><li class="sidebar-sub-header"><a href="/edu-dis-labs/use-cases/#для-зареєстрованого-користувача" class="sidebar-link">Для зареєстрованого користувача</a></li></ul></li></ul></li><li><a href="/edu-dis-labs/design/" class="sidebar-link">Проєктування архітектури системи</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/edu-dis-labs/design/#be-модель" class="sidebar-link">BE модель</a></li><li class="sidebar-sub-header"><a href="/edu-dis-labs/design/#er-модель" class="sidebar-link">ER-модель</a></li><li class="sidebar-sub-header"><a href="/edu-dis-labs/design/#реляціина-схема" class="sidebar-link">Реляційна схема</a></li></ul></li><li><a href="/edu-dis-labs/software/" aria-current="page" class="active sidebar-link">Реалізація інформаційного та програмного забезпечення</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/edu-dis-labs/software/#sql-скрипт-для-створення-та-початкового-наповнення-бази-даних" class="sidebar-link">SQL-скрипт для створення та початкового наповнення бази даних</a></li><li class="sidebar-sub-header"><a href="/edu-dis-labs/software/#restfull-сервіс-для-керування-опитуваннями" class="sidebar-link">RESTfull-сервіс для керування опитуваннями</a></li></ul></li><li><a href="/edu-dis-labs/test/" class="sidebar-link">Тестування працездатності системи</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/edu-dis-labs/test/#передумови" class="sidebar-link">Передумови</a></li><li class="sidebar-sub-header"><a href="/edu-dis-labs/test/#тестування-компонентів" class="sidebar-link">Тестування компонентів</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/edu-dis-labs/test/#api-survey" class="sidebar-link">/api/survey</a></li><li class="sidebar-sub-header"><a href="/edu-dis-labs/test/#api-survey-id" class="sidebar-link">/a
<span class="token keyword">SET</span> <span class="token variable">@OLD_UNIQUE_CHECKS</span><span class="token operator">=</span>@<span class="token variable">@UNIQUE_CHECKS</span><span class="token punctuation">,</span> UNIQUE_CHECKS<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> <span class="token variable">@OLD_FOREIGN_KEY_CHECKS</span><span class="token operator">=</span>@<span class="token variable">@FOREIGN_KEY_CHECKS</span><span class="token punctuation">,</span> FOREIGN_KEY_CHECKS<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> <span class="token variable">@OLD_SQL_MODE</span><span class="token operator">=</span>@<span class="token variable">@SQL_MODE</span><span class="token punctuation">,</span> SQL_MODE<span class="token operator">=</span><span class="token string">'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'</span><span class="token punctuation">;</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Schema mydb</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Schema mydb</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">SCHEMA</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8 <span class="token punctuation">;</span>
<span class="token keyword">USE</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span> <span class="token punctuation">;</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Table `mydb`.`Account`</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Account<span class="token punctuation">`</span> <span class="token punctuation">(</span>
<span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>username<span class="token punctuation">`</span> <span class="token keyword">CHAR</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>password<span class="token punctuation">`</span> <span class="token keyword">CHAR</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">UNIQUE</span> <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>id_UNIQUE<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">ASC</span><span class="token punctuation">)</span> VISIBLE<span class="token punctuation">,</span>
<span class="token keyword">UNIQUE</span> <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>username_UNIQUE<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>username<span class="token punctuation">`</span> <span class="token keyword">ASC</span><span class="token punctuation">)</span> VISIBLE<span class="token punctuation">)</span>
<span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span><span class="token punctuation">;</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Table `mydb`.`Survey`</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Survey<span class="token punctuation">`</span> <span class="token punctuation">(</span>
<span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>isPaused<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>isNamed<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">CHAR</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>duration<span class="token punctuation">`</span> <span class="token keyword">CHAR</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">UNIQUE</span> <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>id_UNIQUE<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">ASC</span><span class="token punctuation">)</span> VISIBLE<span class="token punctuation">,</span>
<span class="token keyword">CONSTRAINT</span> <span class="token punctuation">`</span>fk_Survey_Account1<span class="token punctuation">`</span>
<span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">REFERENCES</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Account<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">ON</span> <span class="token keyword">DELETE</span> <span class="token keyword">NO</span> <span class="token keyword">ACTION</span>
<span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">NO</span> <span class="token keyword">ACTION</span><span class="token punctuation">)</span>
<span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span><span class="token punctuation">;</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Table `mydb`.`Question`</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Question<span class="token punctuation">`</span> <span class="token punctuation">(</span>
<span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span><span class="token keyword">Text</span><span class="token punctuation">`</span> <span class="token keyword">CHAR</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">UNIQUE</span> <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>id_UNIQUE<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">ASC</span><span class="token punctuation">)</span> VISIBLE<span class="token punctuation">,</span>
<span class="token keyword">CONSTRAINT</span> <span class="token punctuation">`</span>fk_Question_Survey1<span class="token punctuation">`</span>
<span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">REFERENCES</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Survey<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">ON</span> <span class="token keyword">DELETE</span> <span class="token keyword">NO</span> <span class="token keyword">ACTION</span>
<span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">NO</span> <span class="token keyword">ACTION</span><span class="token punctuation">)</span>
<span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span><span class="token punctuation">;</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Table `mydb`.`Response`</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Response<span class="token punctuation">`</span> <span class="token punctuation">(</span>
<span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span><span class="token keyword">Value</span><span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">16384</span><span class="token punctuation">)</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token keyword">UNIQUE</span> <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>id_UNIQUE<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">ASC</span><span class="token punctuation">)</span> VISIBLE<span class="token punctuation">,</span>
<span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">CONSTRAINT</span> <span class="token punctuation">`</span>fk_Response_Question<span class="token punctuation">`</span>
<span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">REFERENCES</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Question<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">ON</span> <span class="token keyword">DELETE</span> <span class="token keyword">NO</span> <span class="token keyword">ACTION</span>
<span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">NO</span> <span class="token keyword">ACTION</span><span class="token punctuation">,</span>
<span class="token keyword">CONSTRAINT</span> <span class="token punctuation">`</span>fk_Response_Account1<span class="token punctuation">`</span>
<span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">REFERENCES</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Account<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">ON</span> <span class="token keyword">DELETE</span> <span class="token keyword">NO</span> <span class="token keyword">ACTION</span>
<span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">NO</span> <span class="token keyword">ACTION</span><span class="token punctuation">)</span>
<span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span><span class="token punctuation">;</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Table `mydb`.`Link`</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Link<span class="token punctuation">`</span> <span class="token punctuation">(</span>
<span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>uses<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>responces<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>usageLimit<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>responceLimit<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>path<span class="token punctuation">`</span> <span class="token keyword">CHAR</span><span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">CONSTRAINT</span> <span class="token punctuation">`</span>fk_Link_Survey1<span class="token punctuation">`</span>
<span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">REFERENCES</span> <span class="token punctuation">`</span>mydb<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Survey<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">ON</span> <span class="token keyword">DELETE</span> <span class="token keyword">NO</span> <span class="token keyword">ACTION</span>
<span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">NO</span> <span class="token keyword">ACTION</span><span class="token punctuation">)</span>
<span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> SQL_MODE<span class="token operator">=</span><span class="token variable">@OLD_SQL_MODE</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> FOREIGN_KEY_CHECKS<span class="token operator">=</span><span class="token variable">@OLD_FOREIGN_KEY_CHECKS</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> UNIQUE_CHECKS<span class="token operator">=</span><span class="token variable">@OLD_UNIQUE_CHECKS</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="restfull-сервіс-для-керування-опитуваннями"><a href="#restfull-сервіс-для-керування-опитуваннями" class="header-anchor">#</a> RESTfull-сервіс для керування опитуваннями</h2> <p>Код серверу (Python, Flask):</p> <div class="language-python extra-class"><pre class="language-python"><code><span class="token keyword">from</span> flask <span class="token keyword">import</span> Flask<span class="token punctuation">,</span> request
<span class="token keyword">import</span> mariadb <span class="token keyword">as</span> mdb
<span class="token keyword">import</span> json
<span class="token keyword">import</span> sys
<span class="token keyword">def</span> <span class="token function">init_db</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> mdb<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>host<span class="token operator">=</span><span class="token string">&quot;127.0.0.1&quot;</span><span class="token punctuation">,</span> port<span class="token operator">=</span><span class="token number">3306</span><span class="token punctuation">,</span> user<span class="token operator">=</span><span class="token string">&quot;user&quot;</span><span class="token punctuation">,</span> password<span class="token operator">=</span><span class="token string">&quot;testing432&quot;</span><span class="token punctuation">)</span>
c <span class="token operator">=</span> <span class="token number">0</span>
app <span class="token operator">=</span> Flask<span class="token punctuation">(</span>__name__<span class="token punctuation">)</span>
<span class="token decorator annotation punctuation">@app<span class="token punctuation">.</span>route</span><span class="token punctuation">(</span><span class="token string">&quot;/api/&lt;endpoint&gt;&quot;</span><span class="token punctuation">,</span> methods <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">&quot;GET&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;POST&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;PUT&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;DELETE&quot;</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">api_test</span><span class="token punctuation">(</span>endpoint<span class="token punctuation">)</span><span class="token punctuation">:</span>
se <span class="token operator">=</span> endpoint
match se<span class="token punctuation">:</span>
case <span class="token string">&quot;counter&quot;</span><span class="token punctuation">:</span>
<span class="token keyword">global</span> c
c <span class="token operator">+=</span> <span class="token number">1</span>
case <span class="token string">&quot;account&quot;</span><span class="token punctuation">:</span>
c <span class="token operator">=</span> init_db<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur <span class="token operator">=</span> c<span class="token punctuation">.</span>cursor<span class="token punctuation">(</span><span class="token punctuation">)</span>
match request<span class="token punctuation">.</span>method<span class="token punctuation">:</span>
case <span class="token string">&quot;GET&quot;</span><span class="token punctuation">:</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string">&quot;SELECT id, username FROM odb.account;&quot;</span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">,</span> <span class="token string">&quot;username&quot;</span><span class="token punctuation">:</span> j<span class="token punctuation">}</span> <span class="token keyword">for</span> i<span class="token punctuation">,</span> j <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> json<span class="token punctuation">.</span>dumps<span class="token punctuation">(</span>r<span class="token punctuation">)</span>
case <span class="token string">&quot;POST&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;INSERT INTO odb.account (username, password) VALUES (\&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'username'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'password'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;);&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string">'{&quot;success&quot;: true}\n'</span>
case <span class="token string">&quot;PUT&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;UPDATE odb.account SET username = \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'username'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, password = \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'password'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot; WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string">'{&quot;success&quot;: true}\n'</span>
case <span class="token string">&quot;DELETE&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;SELECT id, username FROM odb.account WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">,</span> <span class="token string">&quot;username&quot;</span><span class="token punctuation">:</span> j<span class="token punctuation">}</span> <span class="token keyword">for</span> i<span class="token punctuation">,</span> j <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;DELETE FROM odb.account WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string-interpolation"><span class="token string">f'</span><span class="token interpolation"><span class="token punctuation">{</span>r<span class="token punctuation">}</span></span><span class="token string">\n'</span></span>
case <span class="token string">&quot;survey&quot;</span><span class="token punctuation">:</span>
c <span class="token operator">=</span> init_db<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur <span class="token operator">=</span> c<span class="token punctuation">.</span>cursor<span class="token punctuation">(</span><span class="token punctuation">)</span>
match request<span class="token punctuation">.</span>method<span class="token punctuation">:</span>
case <span class="token string">&quot;GET&quot;</span><span class="token punctuation">:</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string">&quot;SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey;&quot;</span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;isPaused&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;isNamed&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;name&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;duration&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;account_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">}</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> json<span class="token punctuation">.</span>dumps<span class="token punctuation">(</span>r<span class="token punctuation">)</span>
case <span class="token string">&quot;POST&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;INSERT INTO odb.survey (isPaused, isNamed, name, duration, account_id) VALUES (</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'isPaused'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'isNamed'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'name'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'duration'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'account_id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">);&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string">'{&quot;success&quot;: true}\n'</span>
case <span class="token string">&quot;PUT&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;UPDATE odb.survey SET isPaused = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'isPaused'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, isNamed = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'isNamed'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, name = \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'name'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, duration = \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'duration'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot; WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string">'{&quot;success&quot;: true}\n'</span>
case <span class="token string">&quot;DELETE&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;isPaused&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;isNamed&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;name&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;duration&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;account_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">}</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;DELETE FROM odb.survey WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string-interpolation"><span class="token string">f'</span><span class="token interpolation"><span class="token punctuation">{</span>r<span class="token punctuation">}</span></span><span class="token string">\n'</span></span>
case <span class="token string">&quot;link&quot;</span><span class="token punctuation">:</span>
c <span class="token operator">=</span> init_db<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur <span class="token operator">=</span> c<span class="token punctuation">.</span>cursor<span class="token punctuation">(</span><span class="token punctuation">)</span>
match request<span class="token punctuation">.</span>method<span class="token punctuation">:</span>
case <span class="token string">&quot;GET&quot;</span><span class="token punctuation">:</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string">&quot;SELECT id, uses, responces, usageLimit, responceLimit, path, survey_id FROM odb.link;&quot;</span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;uses&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;responces&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;usageLimit&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;responceLimit&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;path&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;survey_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">}</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> json<span class="token punctuation">.</span>dumps<span class="token punctuation">(</span>r<span class="token punctuation">)</span>
case <span class="token string">&quot;POST&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;INSERT INTO odb.link (usageLimit, responceLimit, path, survey_id) VALUES (</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'usageLimit'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'responceLimit'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'path'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'survey_id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">);&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string">'{&quot;success&quot;: true}\n'</span>
case <span class="token string">&quot;PUT&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;UPDATE odb.link SET uses = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'uses'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, responces = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'responces'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, usageLimit = \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'usageLimit'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, responceLimit = \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'responceLimit'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, path = \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'path'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, survey_id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'survey_id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string"> WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string">'{&quot;success&quot;: true}\n'</span>
case <span class="token string">&quot;DELETE&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;SELECT id, uses, responces, usageLimit, responceLimit, path, survey_id FROM odb.survey WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;uses&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;responces&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;usageLimit&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;responceLimit&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;path&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;survey_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">}</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;DELETE FROM odb.link WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string-interpolation"><span class="token string">f'</span><span class="token interpolation"><span class="token punctuation">{</span>r<span class="token punctuation">}</span></span><span class="token string">\n'</span></span>
case <span class="token string">&quot;question&quot;</span><span class="token punctuation">:</span>
c <span class="token operator">=</span> init_db<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur <span class="token operator">=</span> c<span class="token punctuation">.</span>cursor<span class="token punctuation">(</span><span class="token punctuation">)</span>
match request<span class="token punctuation">.</span>method<span class="token punctuation">:</span>
case <span class="token string">&quot;GET&quot;</span><span class="token punctuation">:</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string">&quot;SELECT id, text, survey_id FROM odb.question;&quot;</span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;text&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;survey_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">}</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> json<span class="token punctuation">.</span>dumps<span class="token punctuation">(</span>r<span class="token punctuation">)</span>
case <span class="token string">&quot;POST&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;INSERT INTO odb.question (text, survey_id) VALUES (\&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'text'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'survey_id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">);&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string">'{&quot;success&quot;: true}\n'</span>
case <span class="token string">&quot;PUT&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;UPDATE odb.question SET text = \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'text'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, survey_id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'survey_id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string"> WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string">'{&quot;success&quot;: true}\n'</span>
case <span class="token string">&quot;DELETE&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;SELECT id, text, survey_id FROM odb.question WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;text&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;survey_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">}</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;DELETE FROM odb.question WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string-interpolation"><span class="token string">f'</span><span class="token interpolation"><span class="token punctuation">{</span>r<span class="token punctuation">}</span></span><span class="token string">\n'</span></span>
case <span class="token string">&quot;responce&quot;</span><span class="token punctuation">:</span>
c <span class="token operator">=</span> init_db<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur <span class="token operator">=</span> c<span class="token punctuation">.</span>cursor<span class="token punctuation">(</span><span class="token punctuation">)</span>
match request<span class="token punctuation">.</span>method<span class="token punctuation">:</span>
case <span class="token string">&quot;GET&quot;</span><span class="token punctuation">:</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string">&quot;SELECT id, value, question_id, account_id FROM odb.responce;&quot;</span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;value&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;question_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;account_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">}</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> json<span class="token punctuation">.</span>dumps<span class="token punctuation">(</span>r<span class="token punctuation">)</span>
case <span class="token string">&quot;POST&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;INSERT INTO odb.responce (text, question_id, account_id) VALUES (\&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'value'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'question_id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'account_id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">);&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string">'{&quot;success&quot;: true}\n'</span>
case <span class="token string">&quot;PUT&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;UPDATE odb.responce SET value = \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'value'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, question_id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'question_id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, account_id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'account_id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string"> WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string">'{&quot;success&quot;: true}\n'</span>
case <span class="token string">&quot;DELETE&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;SELECT id, value, question_id, account_id FROM odb.responce WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;value&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;question_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;account_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">}</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;DELETE FROM odb.responce WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'id'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string-interpolation"><span class="token string">f'</span><span class="token interpolation"><span class="token punctuation">{</span>r<span class="token punctuation">}</span></span><span class="token string">\n'</span></span>
case _<span class="token punctuation">:</span>
<span class="token keyword">return</span> <span class="token string-interpolation"><span class="token string">f&quot;work </span><span class="token interpolation"><span class="token punctuation">{</span>c<span class="token punctuation">}</span></span><span class="token string">\n&quot;</span></span>
<span class="token decorator annotation punctuation">@app<span class="token punctuation">.</span>route</span><span class="token punctuation">(</span><span class="token string">&quot;/api/survey/&lt;no&gt;&quot;</span><span class="token punctuation">,</span> methods <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">&quot;GET&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;PUT&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;DELETE&quot;</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">api_numbered</span><span class="token punctuation">(</span>no<span class="token punctuation">)</span><span class="token punctuation">:</span>
c <span class="token operator">=</span> init_db<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur <span class="token operator">=</span> c<span class="token punctuation">.</span>cursor<span class="token punctuation">(</span><span class="token punctuation">)</span>
match request<span class="token punctuation">.</span>method<span class="token punctuation">:</span>
case <span class="token string">&quot;GET&quot;</span><span class="token punctuation">:</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>no<span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;isPaused&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;isNamed&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;name&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;duration&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;account_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">}</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> json<span class="token punctuation">.</span>dumps<span class="token punctuation">(</span>r<span class="token punctuation">)</span>
case <span class="token string">&quot;PUT&quot;</span><span class="token punctuation">:</span>
d <span class="token operator">=</span> request<span class="token punctuation">.</span>get_json<span class="token punctuation">(</span><span class="token punctuation">)</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;UPDATE odb.survey SET isPaused = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'isPaused'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, isNamed = </span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'isNamed'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">, name = \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'name'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot;, duration = \&quot;</span><span class="token interpolation"><span class="token punctuation">{</span>d<span class="token punctuation">[</span><span class="token string">'duration'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token string">\&quot; WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>no<span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string">'{&quot;success&quot;: true}\n'</span>
case <span class="token string">&quot;DELETE&quot;</span><span class="token punctuation">:</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;SELECT id, isPaused, isNamed, name, duration, account_id FROM odb.survey WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>no<span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
r <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;isPaused&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;isNamed&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;name&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;duration&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">&quot;account_id&quot;</span><span class="token punctuation">:</span> i<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">}</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> cur<span class="token punctuation">]</span>
cur<span class="token punctuation">.</span>execute<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f&quot;DELETE FROM odb.survey WHERE id = </span><span class="token interpolation"><span class="token punctuation">{</span>no<span class="token punctuation">}</span></span><span class="token string">;&quot;</span></span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>commit<span class="token punctuation">(</span><span class="token punctuation">)</span>
c<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">return</span> <span class="token string-interpolation"><span class="token string">f'</span><span class="token interpolation"><span class="token punctuation">{</span>r<span class="token punctuation">}</span></span><span class="token string">\n'</span></span>
</code></pre></div></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Останнє оновлення:</span> <span class="time">5/21/2024, 8:40:46 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
<a href="/edu-dis-labs/design/" class="prev">
Проєктування архітектури системи
</a></span> <span class="next"><a href="/edu-dis-labs/test/">
Тестування працездатності системи
</a>
</span></p></div> </main></div><div class="global-ui"><!----></div></div>
<script src="/edu-dis-labs/assets/js/app.dd23c768.js" defer></script><script src="/edu-dis-labs/assets/js/2.11435098.js" defer></script><script src="/edu-dis-labs/assets/js/24.92136d00.js" defer></script>
</body>
</html>