-
-
Notifications
You must be signed in to change notification settings - Fork 355
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
[QUESTION] Update json field #537
Comments
Support custom function in update. (#537)
I'm getting this error...using postgres 12.2 (I modify the JsonSet function described on docs, for get instead update)
|
postgres has not json_set but jsonb_set, and usage maybe different, please see official docs |
Ok...I get it. Thank you for your time and predisposition. |
OK, this is postgres example: from tortoise.expressions import F
from pypika.terms import Function
class JsonbSet(Function):
def __init__(self, field: F, path: str, value: Any, create_if_missing: bool = False):
super().__init__("jsonb_set", field, path, value, create_if_missing)
json = await JSONFields.create(data_default={"a": 1})
json.data_default = JsonbSet(F("data_default"), "{a}", '3') # in fact '3' is integer
await json.save() And the sql is UPDATE "jsonfields" SET "data_default"=jsonb_set("data_default", '{a}', '3', false) WHERE "id" = 1 |
I have a json field structured like this:
[{"fecha": "31-10-2020 16:00", "doctor": "5d2a1c29-21b9-4a02-846c-171ba65ba0ea", "paciente": {"code": "a4723719-fbd4-4d16-9470-97ea93c3c5dd", "conv": "sebastian muñoz"}}]
Is there a way of update a single attribute of the json field ?...I mean without making a query and extracting the attributes.
return await some_pydantic.from_queryset_single(SomeModel.get(id=id)) <---Not this
something like this..obviously field and attr are examples
return await some_pydantic.from_queryset_single(SomeModel.update(id=id).field(jsonField).attr(fecha='New Date'))
The text was updated successfully, but these errors were encountered: