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
[Dev] 導入 SQLAlchemy 並改寫 pt_repository 的 upsert_user #60
[Dev] 導入 SQLAlchemy 並改寫 pt_repository 的 upsert_user #60
Conversation
增加CUD的使用範例 @auto_commit
def insert_user(**kwargs):
session: Session = kwargs["session"]
data = User(id="1234", chat_id="12", state=1)
session.add(data)
@auto_commit
def update_user(**kwargs):
session: Session = kwargs["session"]
user = session.query(User).filter(User.id == "1234").first()
user.state = 0
@auto_commit
def delete_user(**kwargs):
session: Session = kwargs["session"]
user = session.query(User).filter(User.id == "1234").first()
session.delete(user) |
repository/database.py
Outdated
Engine = create_engine( | ||
f"postgresql://{pt_config.DB_USER}:{pt_config.DB_PASSWORD}@" | ||
f"{pt_config.DB_HOST}:5432/{pt_config.DB_NAME}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5432 port 可以使用目前抽出的 environment DB_PORT
,不過會需要先 rebase。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有rebase了~,但我local的licese怪怪的XD
9b1e108
to
f51ed04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
Why need this change? / Root cause:
Changes made:
upsert_user()
import-outside-toplevel
,因為pt_service裡面有一些func底下有import pt_bot
的行為,如果抽到最上面import,那跑app.py的時候就會重複啟用bot了,或者要把那邊的程式解偶一下Test Scope / Change impact: