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
[Study] 採用 ORM framework #42
Closed
Closed
Conversation
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
s9891326
changed the title
Initial flask-migrate, and create models.py(GoodInfo、User、UserSubGood)
[Study] 採用 ORM framework
Dec 22, 2022
Q: SQL UPDATE 那UPDATE TIME 會更新嗎? @auto_commit
def update_good_stock_state(good_id: str, stock_state: int, **kwargs):
# 對應到 update_good_stock_state(good_id, state)
# r = GoodInfo.query.filter_by(id=good_id).update({"stock_state": stock_state})
r = db.engine.execute(text("update good_info set stock_state=:stock_state where id=:good_id"),
{"stock_state": stock_state, "good_id": good_id})
return r |
也算是合乎預期,可以上 workaround,update 的時候要加上 update_time 欄位的變更,且使用 postgresql 的 now() |
s9891326
force-pushed
the
feature/study_sqlalchemy_flask_migrate
branch
from
December 25, 2022 09:11
d7f05bf
to
bc89e3c
Compare
s9891326
commented
Dec 25, 2022
Comment on lines
+120
to
+122
@app_context | ||
def add_good_info(good_info): | ||
return pt_repository.add_good_info(good_info) | ||
create_good_info(good_info.good_id, good_info.price, good_info.name, good_info.stock_state) |
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.
增加@app_context
來簡化之前說到要用下面這個才能正常跑的問題
with app.app_context():
xxxx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why need this change? / Root cause:
Changes made:
Test Scope / Change impact: