Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soitool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
bachelor-paa-bittet
soitool
Commits
765aea70
Commit
765aea70
authored
5 years ago
by
Anders H. Rebner
Browse files
Options
Downloads
Patches
Plain Diff
Database tilkobles og tabeller lages
parent
32eb76e3
No related branches found
No related tags found
1 merge request
!10
Database setup
Pipeline
#69843
failed
5 years ago
Stage: lint
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
soitool/database.py
+39
-0
39 additions, 0 deletions
soitool/database.py
with
39 additions
and
0 deletions
soitool/database.py
0 → 100644
+
39
−
0
View file @
765aea70
"""
Database.
"""
import
os
import
sqlite3
DBNAME
=
'
Database
'
CURDIR
=
os
.
path
.
dirname
(
__file__
)
DBPATH
=
os
.
path
.
join
(
CURDIR
,
DBNAME
)
# DDL-statements for creating tables
CODEBOOK
=
'
CREATE TABLE CodeBook(Word VARCHAR PRIMARY KEY, Category VARCHAR, Type int DEFAULT 0)
'
CATEGORYWORDS
=
'
CREATE TABLE CategoryWords(Word VARCHAR PRIMARY KEY, Category VARCHAR)
'
BYHEART
=
'
CREATE TABLE ByHeart(Word VARCHAR PRIMARY KEY)
'
class
Database
():
"""
Holds connection to database.
"""
def
__init__
(
self
):
"""
Connect to existing db if found, creates new db if not.
"""
db_exists
=
os
.
path
.
exists
(
DBPATH
)
if
db_exists
:
print
(
'
connecting to existing DB.
'
)
self
.
conn
=
sqlite3
.
connect
(
DBPATH
)
print
(
'
DB-connection established.
'
)
else
:
print
(
'
Creating new DB.
'
)
self
.
conn
=
sqlite3
.
connect
(
DBPATH
)
self
.
create_tables
()
print
(
'
DB created.
'
)
def
create_tables
(
self
):
"""
Create tables Codebook, CategoryWords and ByHeart.
"""
stmts
=
[
CODEBOOK
,
CATEGORYWORDS
,
BYHEART
]
for
stmt
in
stmts
:
self
.
conn
.
execute
(
stmt
)
self
.
conn
.
commit
()
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