-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdb.py
More file actions
42 lines (31 loc) · 1.3 KB
/
db.py
File metadata and controls
42 lines (31 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from configuration import CONNECTION_ROW
"""
Создаём модель для того, чтобы потом использовать её для описания наших таблиц.
Here we creates model. It needs for future using and table describing.
"""
Model = declarative_base(name='Model')
"""
Создаём коннекшен к нашей базе данных, передавая ему креденшеналы и другую
информацию для этого. Пример коннекшен строки вы можете найти в файле
configuration.py.
In next row we creates connection to our database. It receives credential and
another info about connection. More info and full connection sting example
you can find in configuration.py.
"""
engine = create_engine(
CONNECTION_ROW
)
"""
Создаём экземпляр сессии, которая даст нам возможность каждый раз генерировать
новую сессию.
We create instanse of session maker, that gives possibility to create fresh
database session.
"""
Session = sessionmaker(
engine,
autoflush=False,
autocommit=False
)