# โ (๐ / ๐ฆ ๐ฝ) ๐ฝ
**FastAPI** ๐ช ๐ ๏ธ โฎ๏ธ ๐ โ.
๐ฅ ๐ฅ ๐ ๐ ๐ผ โ๏ธ **๐**, ๐ ๐งข โ ๐ฝ.
๐ ๐ช ๐ ๏ธ โซ๏ธ ๐ ๐ โ ๐ฝ ๐:
* **โณ**
* **๐ธ**
* **โณ**
* **๐ธ๐ฒ**
* **โณ**, โ๏ธ.
!!! tip
๐ค ๐ ๐ ๐ โฎ๏ธ **FastAPI** & **๐**, ๐ โ๏ธ ๐ **โ**, ๐ ๐ธ & ๐ ๐งฐ: https://github.com/tiangolo/full-stack-fastapi-couchbase
## ๐ ๐ ๐ฆฒ
๐, ๐ซ ๐ธ ๐ ๐, ๐ด ๐:
```Python hl_lines="3-5"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
## ๐ฌ ๐ โ๏ธ "๐ ๐"
๐ฅ ๐ โ๏ธ โซ๏ธ โช ๐ง ๐ `type` ๐ ๐.
๐ ๐ซ โ ๐, โ๏ธ ๐ ๐ก ๐ ๐ โน ๐ โฎ๏ธ.
```Python hl_lines="9"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
## ๐ฎ ๐ข ๐ค `Bucket`
**๐**, ๐ฅก โ ๐, ๐ ๐ช ๐ ๐.
๐ซ ๐ ๐ ๐ ๐ ๐ธ.
๐ ๐ ๐ฝ ๐ ๐ "๐ฝ" (๐ฏ ๐ฝ, ๐ซ ๐ฝ ๐ฝ).
๐ **โณ** ๐ "๐".
๐, `Bucket` ๐จ ๐ ๐จ๐ป ๐ป โฎ๏ธ ๐ฝ.
๐ ๐ ๐ข ๐:
* ๐ **๐** ๐ (๐ ๐ช ๐ ๐ฐ).
* โ ๐ข โฒ.
* ๐ ๐.
* ๐ค `Bucket` ๐.
* โ ๐ข โฒ.
* ๐จ โซ๏ธ.
```Python hl_lines="12-21"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
## โ Pydantic ๐ท
**๐** "๐" ๐ค "๐ป ๐", ๐ฅ ๐ช ๐ท ๐ซ โฎ๏ธ Pydantic.
### `User` ๐ท
๐ฅ, โก๏ธ โ `User` ๐ท:
```Python hl_lines="24-28"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
๐ฅ ๐ โ๏ธ ๐ ๐ท ๐ *โก ๐ ๏ธ ๐ข*,, ๐ฅ ๐ซ ๐ โซ๏ธ `hashed_password`.
### `UserInDB` ๐ท
๐, โก๏ธ โ `UserInDB` ๐ท.
๐ ๐ โ๏ธ ๐ฝ ๐ ๐ค ๐ช ๐ฝ.
๐ฅ ๐ซ โ โซ๏ธ ๐ฟ Pydantic `BaseModel` โ๏ธ ๐ฟ ๐ ๐ `User`, โฉ๏ธ โซ๏ธ ๐ โ๏ธ ๐ ๐ข `User` โ ๐ฉโโคโ๐จ ๐
:
```Python hl_lines="31-33"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
!!! note
๐ ๐ ๐ฅ โ๏ธ `hashed_password` & `type` ๐ ๐ ๐ ๐ช ๐ฝ.
โ๏ธ โซ๏ธ ๐ซ ๐ ๐ข `User` ๐ท (1๏ธโฃ ๐ฅ ๐ ๐จ *โก ๐ ๏ธ*).
## ๐ค ๐ฉโ๐ป
๐ โ ๐ข ๐ ๐:
* โ ๐.
* ๐ ๐ ๐ โช๏ธโก๏ธ โซ๏ธ.
* ๐ค ๐ โฎ๏ธ ๐ ๐.
* ๐ฎ ๐ ๐ `UserInDB` ๐ท.
๐ ๐ข ๐ ๐ด ๐ก ๐ค ๐ ๐ฉโ๐ป โช๏ธโก๏ธ `username` (โ๏ธ ๐ ๐ ๐ข) ๐ฌ ๐ *โก ๐ ๏ธ ๐ข*, ๐ ๐ช ๐ ๐ช ๐ค-โ๏ธ โซ๏ธ ๐ ๐ & ๐ฎ โ ๐ฏ โซ๏ธ:
```Python hl_lines="36-42"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
### โ-๐ป
๐ฅ ๐ ๐ซ ๐ฐ โฎ๏ธ `f"userprofile::{username}"`, โซ๏ธ ๐ "โ-๐ป".
๐ ๐ข ๐ ๐ฎ ๐ `{}` โ-๐ป ๐ โ / ๐ ๐ป.
### `dict` ๐
๐ฅ ๐ ๐ซ ๐ฐ โฎ๏ธ `UserInDB(**result.value)`, โซ๏ธ โ๏ธ `dict` "๐".
โซ๏ธ ๐ โ `dict` `result.value`, & โ ๐ ๐ฎ ๐ & ๐ฒ & ๐ถโโ๏ธ ๐ซ ๐-๐ฒ `UserInDB` ๐จ๐ป โ.
, ๐ฅ `dict` ๐:
```Python
{
"username": "johndoe",
"hashed_password": "some_hash",
}
```
โซ๏ธ ๐ ๐ถโโ๏ธ `UserInDB` :
```Python
UserInDB(username="johndoe", hashed_password="some_hash")
```
## โ ๐ **FastAPI** ๐
### โ `FastAPI` ๐ฑ
```Python hl_lines="46"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
### โ *โก ๐ ๏ธ ๐ข*
๐ ๐ ๐ค ๐ & ๐ฅ ๐ซ โ๏ธ ๐ฅผ ๐ await
๐โ๐ฆบ, ๐ฅ ๐ ๐ฃ ๐ ๐ข โฎ๏ธ ๐ `def` โฉ๏ธ `async def`.
, ๐ ๐ ๐ซ โ๏ธ ๐ `Bucket` ๐ ๐ "๐งตโ",, ๐ฅ ๐ช ๐ค ๐ฅก ๐ & ๐ถโโ๏ธ โซ๏ธ ๐ ๐ ๐ข:
```Python hl_lines="49-53"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```
## ๐
๐ ๐ช ๐ ๏ธ ๐ ๐ฅ ๐ฅณ โ ๐ฝ, โ๏ธ ๐ซ ๐ฉ ๐ฆ.
๐ โ ๐ ๐ ๐ข ๐งฐ, โ๏ธ โ๏ธ ๐ ๏ธ.