-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrey
committed
Oct 11, 2024
1 parent
b0d225a
commit f3f9200
Showing
5 changed files
with
56 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ | |
venv/ | ||
.pytest_cache/ | ||
**__pycache__/ | ||
**db.sqlite3 | ||
*.sqlite | ||
*.db |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
# from models import Actor | ||
# from managers import ActorManager | ||
# | ||
from modules.models import Actor | ||
from modules.managers import ActorManager | ||
|
||
# if __name__ == "__main__": | ||
# Actor.objects = ActorManager() | ||
# | ||
# Actor.objects.create(first_name="Emma", last_name="Watson") | ||
# Actor.objects.create(first_name="Daniel", last_name="Radclife") | ||
# print(Actor.objects.all()) | ||
# Actor.objects.update(2, "Daniel", "Radcliffe") | ||
# print(Actor.objects.all()) | ||
# Actor.objects.delete(1) | ||
# print(Actor.objects.all()) | ||
|
||
# Actor.objects.create(first_name="Emma", last_name="Watson") | ||
# Actor.objects.create(first_name="Daniel", last_name="Radclife") | ||
# print(Actor.objects.all()) | ||
# Actor.objects.update(3, "Daniel", "Radcliffe") | ||
# print(Actor.objects.all()) | ||
# Actor.objects.delete(2) | ||
# print(Actor.objects.all()) |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import sqlite3 | ||
from models import Actor | ||
|
||
|
||
class ActorManager: | ||
def __init__(self) -> None: | ||
self._connection = sqlite3.connect('../cinema.sqlite') | ||
self.table_name = 'actors' | ||
|
||
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[Actor]: | ||
actor_format_cursor = self._connection.execute( | ||
f"SELECT * FROM {self.table_name}" | ||
) | ||
return [Actor(*actor) for actor in actor_format_cursor] | ||
|
||
def update(self, actor_id: int, first_name: str, last_name: str) -> None: | ||
self._connection.execute( | ||
f"UPDATE {self.table_name} SET first_name=?, last_name=? WHERE id=?", | ||
(first_name, last_name, actor_id) | ||
) | ||
self._connection.commit() | ||
|
||
def delete(self, actor_id: int) -> None: | ||
self._connection.execute( | ||
f"DELETE FROM {self.table_name} WHERE id=?", | ||
(actor_id,) | ||
) | ||
self._connection.commit() |
This file contains 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
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 |