Skip to content

Esafonova#94

Open
SafonovaEkaterina wants to merge 2 commits into
mainfrom
esafonova
Open

Esafonova#94
SafonovaEkaterina wants to merge 2 commits into
mainfrom
esafonova

Conversation

@SafonovaEkaterina
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown
Owner

@IlyaOrlov IlyaOrlov left a comment

Choose a reason for hiding this comment

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

Есть пара замечаний!


class SqLiteWrapper:
def __init__(self, db_name):
with sq.connect(db_name) as self.con:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

"Класс с возможностями менеджера контекста" предполагает реализацию в классе методов __enter__ и __exit__. В первом коннект к базе открывается, во втором закрывается.


def select(self, req):
self.cur.execute(req)
data = self.cur.fetchall()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Чтоб было проще работать с результатом запроса, как со словарем, стоит выполнить такую донастройку коннекшена: conn.row_factory = sqlite3.Row

return json.dumps(response)

def execute(self, req):
self.cur.executescript(req)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

А где commit? Без него изменения не применятся!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants