mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-10 01:50:08 -04:00
📝 Update docs, typos, aclarations, fix examples
for NoSQL models
This commit is contained in:
@@ -11,10 +11,12 @@ USERPROFILE_DOC_TYPE = "userprofile"
|
||||
|
||||
|
||||
def get_bucket():
|
||||
cluster = Cluster("couchbase://couchbasehost:8091")
|
||||
cluster = Cluster("couchbase://couchbasehost:8091?fetch_mutation_tokens=1&operation_timeout=30&n1ql_timeout=300")
|
||||
authenticator = PasswordAuthenticator("username", "password")
|
||||
cluster.authenticate(authenticator)
|
||||
bucket: Bucket = cluster.open_bucket("bucket_name", lockmode=LOCKMODE_WAIT)
|
||||
bucket.timeout = 30
|
||||
bucket.n1ql_timeout = 300
|
||||
return bucket
|
||||
|
||||
|
||||
@@ -29,9 +31,6 @@ class UserInDB(User):
|
||||
type: str = USERPROFILE_DOC_TYPE
|
||||
hashed_password: str
|
||||
|
||||
class Meta:
|
||||
key: Optional[str] = None
|
||||
|
||||
|
||||
def get_user(bucket: Bucket, username: str):
|
||||
doc_id = f"userprofile::{username}"
|
||||
@@ -39,7 +38,6 @@ def get_user(bucket: Bucket, username: str):
|
||||
if not result.value:
|
||||
return None
|
||||
user = UserInDB(**result.value)
|
||||
user.Meta.key = result.key
|
||||
return user
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Tuple, Set
|
||||
from typing import Set, Tuple
|
||||
|
||||
|
||||
def process_items(items_t: Tuple[int], items_s: Set[bytes]):
|
||||
|
||||
@@ -4,4 +4,4 @@ class Person:
|
||||
|
||||
|
||||
def get_person_name(one_person: Person):
|
||||
return one_person.name
|
||||
return one_person.name
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class User(BaseModel):
|
||||
id: int
|
||||
name = 'John Doe'
|
||||
name = "John Doe"
|
||||
signup_ts: datetime = None
|
||||
friends: List[int] = []
|
||||
|
||||
external_data = {'id': '123', 'signup_ts': '2017-06-01 12:22', 'friends': [1, '2', b'3']}
|
||||
|
||||
external_data = {
|
||||
"id": "123",
|
||||
"signup_ts": "2017-06-01 12:22",
|
||||
"friends": [1, "2", b"3"],
|
||||
}
|
||||
user = User(**external_data)
|
||||
print(user)
|
||||
# > User id=123 name='John Doe' signup_ts=datetime.datetime(2017, 6, 1, 12, 22) friends=[1, 2, 3]
|
||||
|
||||
Reference in New Issue
Block a user