Skip to content
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

Conversation

Yoshino-Yukitaro
Copy link

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.

@codecov
Copy link

codecov bot commented Jun 22, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cf73051) 100.00% compared to head (666cdc4) 100.00%.
Report is 1217 commits behind head on master.

❗ Current head 666cdc4 differs from pull request most recent head a8022e6. Consider uploading reports for the commit a8022e6 to get more accurate results

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.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 666cdc4 at: https://62b2bd06f8dafd4909da75ef--fastapi.netlify.app

@Yoshino-Yukitaro Yoshino-Yukitaro changed the title Add Japanese translation for - docs/ja/docs/tutorial/sql-databases.md 🌐Add Japanese translation for - docs/ja/docs/tutorial/sql-databases.md Jun 22, 2022
@Yoshino-Yukitaro Yoshino-Yukitaro changed the title 🌐Add Japanese translation for - docs/ja/docs/tutorial/sql-databases.md 🌐 Add Japanese translation for - docs/ja/docs/tutorial/sql-databases.md Jun 22, 2022
@Yoshino-Yukitaro Yoshino-Yukitaro changed the title 🌐 Add Japanese translation for - docs/ja/docs/tutorial/sql-databases.md 🌐 Add Japanese translation for docs/ja/docs/tutorial/sql-databases.md Jun 22, 2022
@tiangolo tiangolo changed the title 🌐 Add Japanese translation for docs/ja/docs/tutorial/sql-databases.md 🌐 Add Japanese translation for docs/ja/docs/tutorial/sql-databases.md Jul 14, 2022
@tiangolo tiangolo added lang-all Translations lang-ja Japanese translations awaiting-review labels Jul 14, 2022
@github-actions github-actions bot mentioned this pull request Jul 14, 2022
Copy link
Contributor

@komtaki komtaki left a 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.


この例では **SQLite** を使用します。なぜなら、SQLiteは単一のファイルを使用し、Pythonが完全にサポートしているからです。そのため、この例をコピーして、そのまま実行することができます。

その後、本番のアプリケーションでは **PostgreSQL** のようなデータベースサーバーを使用したいと思うかもしれません。

This comment was marked as outdated.

ファイル `__init__.py` はただの空ファイルですが、このファイルは `sql_app` とそのモジュール (Python ファイル) がパッケージであることを Python に知らせます。

では、それぞれのファイル/モジュールが何をするのか見てみましょう。

This comment was marked as outdated.


### `SessionLocal` クラスの作成

SessionLocal` クラスの各インスタンスがデータベースセッションになります。このクラス自身は、まだデータベースセッションではありません。

This comment was marked as outdated.


では、クラスを返す関数 `declarative_base()` を使ってみましょう。

後で、このクラスを継承して、各データベースモデルやクラス(ORMモデル)を作成します:

This comment was marked as outdated.


そして、Alembicを「マイグレーション」にも使うことになります(それが主な仕事です)。

マイグレーション "とは、SQLAlchemy のモデルの構造を変更したり、新しい属性を追加した りするたびに、それらの変更をデータベースに再現し、新しいカラムやテーブルを追加する ために必要な一連のステップのことです。

This comment was marked as resolved.


## すべてのファイルを確認する

my_super_project`というディレクトリがあり、その中に `sql_app` というサブディレクトリがあることを思い出してください。

This comment was marked as outdated.


そしたら、ブラウザで <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.


この場合、すべてのリクエストを通じて単一のデータベースセッションが使用され、その後(ミドルウェアで)クローズされることを保証するのに役立ちます。

### yield` やミドルウェアとの依存関係

This comment was marked as resolved.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2022

📝 Docs preview for commit e8dee01 at: https://638db9fafc1d98674e565e28--fastapi.netlify.app

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2022

📝 Docs preview for commit 1e7df12 at: https://638dc1e264c021747929c4e1--fastapi.netlify.app

@Yoshino-Yukitaro
Copy link
Author

Yoshino-Yukitaro commented Dec 5, 2022

Thanks for your review @komtaki !
As all the comments make sense, I've fixed them in 1e7df12 .

Copy link
Contributor

@komtaki komtaki left a 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 👍

Copy link
Contributor

@tokusumi tokusumi left a 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(リレーショナル)データベースを使用する必要はありません。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
**FastAPI** では、SQLリレーショナル)データベースを使用する必要はありません
**FastAPI** では、SQL (リレーショナル) データベースは必須ではありません

more natural, I guess


**FastAPI** では、SQL(リレーショナル)データベースを使用する必要はありません。

しかし、使いたいリレーショナルデータベースを使用することができます。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
しかし、使いたいリレーショナルデータベースを使用することができます
しかし、任意のリレーショナルデータベースを使用できます

it's easier?


ここでは、 <a href="https://www.sqlalchemy.org/" class="external-link" target="_blank">SQLAlchemy</a>を使った例を見てみましょう。

以下のような、SQLAlchemyがサポートするどのようなデータベースにも簡単に適応できます。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
以下のような、SQLAlchemyがサポートするどのようなデータベースにも簡単に適応できます
以下のような、SQLAlchemyがサポートするデータベースを簡単に適応できます

"you can adapt it" means 「それ (database) をFastAPIに適応させることが可能」here


そして、そのクラスの各 *インスタンス* オブジェクトは、データベースの行を表します。

例えば、 `orion_cat` (`Pet` のインスタンス) オブジェクトが `orion_cat.type` という属性を持つなら、そのカラムは `type` であると考えられる。そしてその属性の値は、例えば `"cat"` とすることができる。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
例えば、 `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は、テーブルやエンティティ間の接続やリレーションを作成するツールも備えている。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
これらのORMは、テーブルやエンティティ間の接続やリレーションを作成するツールも備えている
これらのORMは、テーブルやエンティティ間の接続やリレーションを作成するツールも備えています

same as above


`item.dict()`

そして、`dict` の key-value ペアを SQLAlchemy の `Item` へのキーワード引数として渡しています。次のように。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
そして、`dict` の key-value ペアを SQLAlchemy の `Item` へのキーワード引数として渡しています。次のように
そして次のように、`dict` の key-value ペアを SQLAlchemy の `Item` へのキーワード引数として渡しています。

more natural


`Item(**item.dict())`

さらに、Pydantic *model* が提供しない別のキーワード引数 `owner_id` を、渡します。次のように。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
さらに、Pydantic *model* が提供しない別のキーワード引数 `owner_id` を、渡します。次のように
さらに次のように、Pydantic *model* が提供しない別のキーワード引数 `owner_id` を渡します

more natural

これによって、*path operation function* の内部から直接 `crud.get_user` を呼び出して、そのセッションを使用することができます。

!!! Tip "豆知識"
返す値は、SQLAlchemy のモデル、あるいは SQLAlchemy のモデルのリストである ことに注意してください。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
返す値は、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> を開けます。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
そしたら、ブラウザで <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` の動作にはあまり問題はないでしょうけど。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* もっとも、ここでは `SQLAlchemy` の動作にはあまり問題はないでしょうけど
* もっとも、ここでは `SQLAlchemy` の動作にはあまり問題はないでしょう

too conversational

@github-actions
Copy link
Contributor

📝 Docs preview for commit fcf8f60 at: https://639ce54289c20f03eba4cebb--fastapi.netlify.app

@tiangolo
Copy link
Owner

📝 Docs preview for commit a8022e6 at: https://649a1931d1bbbc12fe60f919--fastapi.netlify.app

@tiangolo
Copy link
Owner

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.

@tiangolo tiangolo closed this Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants