Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Slack Commands
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timon Dörzapf
Slack Commands
Commits
9c1e29bc
Commit
9c1e29bc
authored
9 months ago
by
Timon Dörzapf
Browse files
Options
Downloads
Patches
Plain Diff
Implemented database
parent
a64916f1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backendserver/db.py
+47
-0
47 additions, 0 deletions
backendserver/db.py
backendserver/db_data.py
+44
-0
44 additions, 0 deletions
backendserver/db_data.py
with
91 additions
and
0 deletions
backendserver/db.py
0 → 100644
+
47
−
0
View file @
9c1e29bc
import
sqlite3
import
db_data
DB_NAME
=
'
dispenser.db
'
class
DB
():
def
__init__
(
self
):
self
.
db
=
sqlite3
.
connect
(
DB_NAME
,
check_same_thread
=
False
)
self
.
cursor
=
self
.
db
.
cursor
()
self
.
cursor
.
execute
(
db_data
.
CREATE_DISPENSES
)
# Create patients data
self
.
cursor
.
execute
(
db_data
.
CREATE_PATIENTS
)
self
.
db
.
commit
()
def
reset
(
self
):
self
.
cursor
.
execute
(
db_data
.
DROP_DISPENSES
)
self
.
cursor
.
execute
(
db_data
.
CREATE_DISPENSES
)
self
.
cursor
.
execute
(
db_data
.
DROP_PATIENTS
)
self
.
cursor
.
execute
(
db_data
.
CREATE_PATIENTS
)
for
patient
in
db_data
.
PATIENS
:
self
.
cursor
.
execute
(
db_data
.
INSERT_PATIENT
,
patient
)
self
.
db
.
commit
()
def
dispense
(
self
,
patient_id
,
time
):
self
.
cursor
.
execute
(
db_data
.
INSERT_DISPENSE
,
(
patient_id
,
time
))
self
.
db
.
commit
()
def
select
(
self
):
self
.
cursor
.
execute
(
'''
SELECT * FROM dispenses
'''
)
return
self
.
cursor
.
fetchall
()
def
delete
(
self
,
id
):
self
.
cursor
.
execute
(
'''
DELETE FROM dispenses
WHERE id = ?
'''
,
(
id
,))
self
.
db
.
commit
()
def
clear
(
self
):
self
.
cursor
.
execute
(
'''
DELETE FROM dispenses
'''
)
# Remove dispenses table
self
.
cursor
.
execute
(
db_data
.
DROP_DISPENSES
)
self
.
db
.
commit
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
backendserver/db_data.py
0 → 100644
+
44
−
0
View file @
9c1e29bc
CREATE_DISPENSES
=
'''
CREATE TABLE IF NOT EXISTS dispenses(
id INTEGER PRIMARY KEY,
patient_id INTEGER,
time TEXT
)
'''
CREATE_PATIENTS
=
'''
CREATE TABLE IF NOT EXISTS patients(
id INTEGER PRIMARY KEY,
name TEXT,
age INTEGER,
weight INTEGER,
height INTEGER
)
'''
DROP_DISPENSES
=
'''
DROP TABLE IF EXISTS dispenses
'''
DROP_PATIENTS
=
'''
DROP TABLE IF EXISTS patients
'''
INSERT_PATIENT
=
'''
INSERT INTO patients(name, age, weight, height)
VALUES(?, ?, ?, ?)
'''
INSERT_DISPENSE
=
'''
INSERT INTO dispenses(patient_id, time)
VALUES(?, ?)
'''
PATIENS
=
[
(
'
John Doe
'
,
25
,
70
,
170
),
(
'
Jane Doe
'
,
30
,
60
,
160
),
(
'
John Smith
'
,
40
,
80
,
180
),
(
'
Jane Smith
'
,
35
,
65
,
165
),
(
'
John Brown
'
,
45
,
85
,
175
),
(
'
Jane Brown
'
,
50
,
55
,
155
)
]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment