Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commit #945

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/actors.db

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove database file

Binary file not shown.
13 changes: 0 additions & 13 deletions app/main.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you didn't have to delete this file - just needed to revert changes that you did. Make it look like the file on master and that's it

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert changes to main.py - it should look exactly like on master branch

This file was deleted.

65 changes: 65 additions & 0 deletions app/managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import sqlite3

from models import Actor


class ActorManager:
def __init__(self) -> None:
self._connection = sqlite3.connect("cinema.db")
self.create_table()
self.table_name = "actors"

def create_table(self) -> None:
self._connection.execute(
"""
CREATE TABLE IF NOT EXISTS actors (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad sql formatting. You can use this to make it pretty https://sqlformat.org/
Apply everywhere

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually here you can keep as is - sql formatter will spread lines too much. But check other queries - the least you can do is to put each keyword on new line - thats the standard

id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL
)
"""
)
self._connection.commit()

def create(self, first_name: str, last_name: str) -> None:
self._connection.execute(
f"""
INSERT INTO {self.table_name}
(first_name, last_name) VALUES (?, ?)
""",
(first_name, last_name)
)
self._connection.commit()

def all(self) -> list:
cinema_cursor = self._connection.execute(
"SELECT * FROM actors"
)
return [
Actor(*row) for row in cinema_cursor
]

def update(
self,
id_: int,
new_first_name: str,
new_last_name: str
) -> None:
self._connection.execute(
f"""
UPDATE {self.table_name}
SET first_name = ?, last_name = ?
WHERE id = ?""",
(new_first_name, new_last_name, id_)
)
self._connection.commit()

def delete(self, id_delete: int) -> None:
self._connection.execute(
f"""
DELETE FROM {self.table_name}
WHERE id = ?
""",
(id_delete,)
)
self._connection.commit()
8 changes: 8 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from dataclasses import dataclass


@dataclass
class Actor:
id: int
first_name: str
last_name: str
Binary file added cinema.sqlite

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove database file

Binary file not shown.
Loading