Created
October 5, 2021 12:49
-
-
Save opalczynski/604d5243cdcf3f9838cd517bab1c0c17 to your computer and use it in GitHub Desktop.
SQLite database for the tasks management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os.path | |
| import sqlite3 | |
| class Database: | |
| PROJECT_SQL = """CREATE TABLE project ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| name text, | |
| description text NULL);""" | |
| TASK_SQL = """CREATE TABLE task ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| title text, | |
| description text, | |
| status integer, | |
| project_id integer, | |
| FOREIGN KEY(project_id) REFERENCES project(id));""" | |
| def _db_exists(self): | |
| return os.path.exists("todos.db") | |
| def get_connection(self): | |
| return sqlite3.connect("todos.db") | |
| def initialize(self): | |
| if self._db_exists(): | |
| return | |
| connection = self.get_connection() | |
| cursor = connection.cursor() | |
| cursor.execute(self.PROJECT_SQL) | |
| cursor.execute(self.TASK_SQL) | |
| connection.commit() | |
| connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment