📝 Update docs, typos, aclarations, fix examples

for NoSQL models
This commit is contained in:
Sebastián Ramírez
2018-12-17 22:50:22 +04:00
parent 2a48b10be3
commit 659b8ae8af
11 changed files with 34 additions and 45 deletions

View File

@@ -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

View File

@@ -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]):

View File

@@ -4,4 +4,4 @@ class Person:
def get_person_name(one_person: Person):
return one_person.name
return one_person.name

View File

@@ -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]