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
🌐 Add Japanese translation for docs/ja/docs/tutorial/sql-databases.md
#5058
🌐 Add Japanese translation for docs/ja/docs/tutorial/sql-databases.md
#5058
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5058 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 540 532 -8
Lines 13969 13672 -297
==========================================
- Hits 13969 13672 -297 ☔ View full report in Codecov by Sentry. |
📝 Docs preview for commit 666cdc4 at: https://62b2bd06f8dafd4909da75ef--fastapi.netlify.app |
docs/ja/docs/tutorial/sql-databases.md
docs/ja/docs/tutorial/sql-databases.md
docs/ja/docs/tutorial/sql-databases.md
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.
I'm appreciate for your tough contribution. 👏
I commented a few suggestion, so please confirm.
その後、本番のアプリケーションでは **PostgreSQL** のようなデータベースサーバーを使用したいと思うかもしれません。 | ||
|
||
!!! Tip "豆知識" | ||
**FastAPI** と **PostgreSQL** を使った公式のプロジェクトジェネレータがあります。これはフロントエンドやその他のツールを含んでおり、全て **Docker** を基にしています。 <a href="https://github.com/tiangolo/full-stack-fastapi-postgresql" class="external-link" target="_blank">https://github.com/tiangolo/full-stack-fastapi-postgresql</a> |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
||
この例では **SQLite** を使用します。なぜなら、SQLiteは単一のファイルを使用し、Pythonが完全にサポートしているからです。そのため、この例をコピーして、そのまま実行することができます。 | ||
|
||
その後、本番のアプリケーションでは **PostgreSQL** のようなデータベースサーバーを使用したいと思うかもしれません。 |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
ファイル `__init__.py` はただの空ファイルですが、このファイルは `sql_app` とそのモジュール (Python ファイル) がパッケージであることを Python に知らせます。 | ||
|
||
では、それぞれのファイル/モジュールが何をするのか見てみましょう。 | ||
|
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
||
### `SessionLocal` クラスの作成 | ||
|
||
SessionLocal` クラスの各インスタンスがデータベースセッションになります。このクラス自身は、まだデータベースセッションではありません。 |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
||
では、クラスを返す関数 `declarative_base()` を使ってみましょう。 | ||
|
||
後で、このクラスを継承して、各データベースモデルやクラス(ORMモデル)を作成します: |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
||
そして、Alembicを「マイグレーション」にも使うことになります(それが主な仕事です)。 | ||
|
||
マイグレーション "とは、SQLAlchemy のモデルの構造を変更したり、新しい属性を追加した りするたびに、それらの変更をデータベースに再現し、新しいカラムやテーブルを追加する ために必要な一連のステップのことです。 |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
||
## すべてのファイルを確認する | ||
|
||
my_super_project`というディレクトリがあり、その中に `sql_app` というサブディレクトリがあることを思い出してください。 |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
||
そしたら、ブラウザで <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a> を開けます。 | ||
|
||
そして、実際のデータベースからデータを読み出しながら、**FastAPI**アプリケーションと対話することができるようになります: |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
||
この場合、すべてのリクエストを通じて単一のデータベースセッションが使用され、その後(ミドルウェアで)クローズされることを保証するのに役立ちます。 | ||
|
||
### yield` やミドルウェアとの依存関係 |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
📝 Docs preview for commit e8dee01 at: https://638db9fafc1d98674e565e28--fastapi.netlify.app |
📝 Docs preview for commit 1e7df12 at: https://638dc1e264c021747929c4e1--fastapi.netlify.app |
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.
Thanks for your improvement.
LGTM 👍
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.
Thank you for your first contribution!!!
It's really helpful to translate long but important chapter like this.
I would have some proposal to polish this more.
@@ -0,0 +1,787 @@ | |||
# SQL (リレーショナル) データベース | |||
|
|||
**FastAPI** では、SQL(リレーショナル)データベースを使用する必要はありません。 |
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.
**FastAPI** では、SQL(リレーショナル)データベースを使用する必要はありません。 | |
**FastAPI** では、SQL (リレーショナル) データベースは必須ではありません。 |
more natural, I guess
|
||
**FastAPI** では、SQL(リレーショナル)データベースを使用する必要はありません。 | ||
|
||
しかし、使いたいリレーショナルデータベースを使用することができます。 |
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.
しかし、使いたいリレーショナルデータベースを使用することができます。 | |
しかし、任意のリレーショナルデータベースを使用できます。 |
it's easier?
|
||
ここでは、 <a href="https://www.sqlalchemy.org/" class="external-link" target="_blank">SQLAlchemy</a>を使った例を見てみましょう。 | ||
|
||
以下のような、SQLAlchemyがサポートするどのようなデータベースにも簡単に適応できます。 |
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.
以下のような、SQLAlchemyがサポートするどのようなデータベースにも簡単に適応できます。 | |
以下のような、SQLAlchemyがサポートするデータベースを簡単に適応できます。 |
"you can adapt it" means 「それ (database) をFastAPIに適応させることが可能」here
|
||
そして、そのクラスの各 *インスタンス* オブジェクトは、データベースの行を表します。 | ||
|
||
例えば、 `orion_cat` (`Pet` のインスタンス) オブジェクトが `orion_cat.type` という属性を持つなら、そのカラムは `type` であると考えられる。そしてその属性の値は、例えば `"cat"` とすることができる。 |
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.
例えば、 `orion_cat` (`Pet` のインスタンス) オブジェクトが `orion_cat.type` という属性を持つなら、そのカラムは `type` であると考えられる。そしてその属性の値は、例えば `"cat"` とすることができる。 | |
例えば、 `orion_cat` (`Pet` のインスタンス) オブジェクトが `orion_cat.type` という属性を持つなら、そのカラムは `type` であると考えられます。そしてその属性の値は、例えば `"cat"` とすることができます。 |
you should unify with ですます調
|
||
例えば、 `orion_cat` (`Pet` のインスタンス) オブジェクトが `orion_cat.type` という属性を持つなら、そのカラムは `type` であると考えられる。そしてその属性の値は、例えば `"cat"` とすることができる。 | ||
|
||
これらのORMは、テーブルやエンティティ間の接続やリレーションを作成するツールも備えている。 |
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.
これらのORMは、テーブルやエンティティ間の接続やリレーションを作成するツールも備えている。 | |
これらのORMは、テーブルやエンティティ間の接続やリレーションを作成するツールも備えています。 |
same as above
|
||
`item.dict()` | ||
|
||
そして、`dict` の key-value ペアを SQLAlchemy の `Item` へのキーワード引数として渡しています。次のように。 |
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.
そして、`dict` の key-value ペアを SQLAlchemy の `Item` へのキーワード引数として渡しています。次のように。 | |
そして次のように、`dict` の key-value ペアを SQLAlchemy の `Item` へのキーワード引数として渡しています。 |
more natural
|
||
`Item(**item.dict())` | ||
|
||
さらに、Pydantic *model* が提供しない別のキーワード引数 `owner_id` を、渡します。次のように。 |
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.
さらに、Pydantic *model* が提供しない別のキーワード引数 `owner_id` を、渡します。次のように。 | |
さらに次のように、Pydantic *model* が提供しない別のキーワード引数 `owner_id` を渡します。 |
more natural
これによって、*path operation function* の内部から直接 `crud.get_user` を呼び出して、そのセッションを使用することができます。 | ||
|
||
!!! Tip "豆知識" | ||
返す値は、SQLAlchemy のモデル、あるいは SQLAlchemy のモデルのリストである ことに注意してください。 |
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.
返す値は、SQLAlchemy のモデル、あるいは SQLAlchemy のモデルのリストである ことに注意してください。 | |
返す値は、SQLAlchemy のモデル、あるいは SQLAlchemy のモデルのリストであることに注意してください。 |
typo
|
||
</div> | ||
|
||
そしたら、ブラウザで <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a> を開けます。 |
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.
そしたら、ブラウザで <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a> を開けます。 | |
そうすると、ブラウザで <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a> を開けます。 |
too conversational
* より多くのコードを必要とし、少し複雑になっています。 | ||
* ミドルウェアは `async` 関数である必要があります。 | ||
* その中に、ネットワークを「待つ」必要があるコードがあると、そこでアプリケーションが「ブロック」され、パフォーマンスが少し低下する可能性があります。 | ||
* もっとも、ここでは `SQLAlchemy` の動作にはあまり問題はないでしょうけど。 |
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.
* もっとも、ここでは `SQLAlchemy` の動作にはあまり問題はないでしょうけど。 | |
* もっとも、ここでは `SQLAlchemy` の動作にはあまり問題はないでしょう。 |
too conversational
📝 Docs preview for commit fcf8f60 at: https://639ce54289c20f03eba4cebb--fastapi.netlify.app |
📝 Docs preview for commit a8022e6 at: https://649a1931d1bbbc12fe60f919--fastapi.netlify.app |
As this PR had requested changes to be applied but has been inactive for a while, it's now going to be closed. But if there's anyone interested, feel free to create a new PR. |
Relates to #1572
This PR translates tutorial/sql-databases.md.
I am Japanese and I love FastAPI, so I translated it.
This is my first pull request for this repository, so I apologize if there are any problems. I would appreciate it if you could check it.