redis-om-python
redis-om-python copied to clipboard
How to replace default primary key?
I have two use cases in which I would like to replace the default pk field with another field:
-
I would like to define that a string field named "uuid" to be my primary key field, instead of the default "pk". I do want to keep the ULID key generator, but just to set it into a field named "uuid" instead of "pk".
-
same as #1, just skipping the ULID key generator, allowing me to set the primary key manually.
Is it possible to achieve? I would like to achieve it for both Json and Hash models. The documentation on that aspect is not clear enough.
Thanks in advance for anyone who will help.
Using the readme example:
import datetime
from typing import Optional
from pydantic import EmailStr
from redis_om import HashModel
class Customer(HashModel):
first_name: str
last_name: str
email: EmailStr
join_date: datetime.date
age: int
bio: Optional[str]
uuid= "46b8d309-c085-4b52-b88c-7c906a8e6cea"
andrew = Customer(
pk= uuid,
first_name="Andrew",
last_name="Brookins",
email="[email protected]",
join_date=datetime.date.today(),
age=38,
bio="Python developer, works at Redis, Inc."
)
customer = Customer.get(uuid)
@simonprickett seems like this has been addressed and should be closed
Using the readme example:
import datetime from typing import Optional from pydantic import EmailStr from redis_om import HashModel class Customer(HashModel): first_name: str last_name: str email: EmailStr join_date: datetime.date age: int bio: Optional[str]
uuid= "46b8d309-c085-4b52-b88c-7c906a8e6cea" andrew = Customer( pk= uuid, first_name="Andrew", last_name="Brookins", email="[email protected]", join_date=datetime.date.today(), age=38, bio="Python developer, works at Redis, Inc." ) customer = Customer.get(uuid)
This solves question 2 but not question 1
The field name is still pk