You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classMyDetails(BaseModel):
unique_id_field: strother_field: str@app.get("/details")defdetails(unique_identifier: str) ->MyDetails:
# for now, library users need to inject an appropriate FILTER clause themselves, or# just pass any query as long as it only returns one result when run through the mapper.# (this solution is still a bit ugly because the query needs to refer to the binding var,# not the model field)query=f"""SELECT ?unique_id_field ?other_field WHERE { ... FILTER (?unique_id_field="{unique_identifier}"^^xsd:string) \}"""adapter=SPARQLModelAdapter(
target="https://graphdb.r11.eu/repositories/RELEVEN",
query=query,
model=Details,
)
returnadapter.query_one()
With the 0-argument approach to query_one(), it is necessary to dynamically create a query with an appropriate FILTER (which needs to refer to the binding variable) in the endpoint definition. Since rdfproxy will anyhow soon have the capability to inject FILTERs (for the new model_bool implementation), it would be nice if it was also possible to pass a minimal filter argument (which can refer to the model fields) to query_one(), with rdfproxy taking care of injecting the appropriate filter. Example usage:
classMyDetails(BaseModel):
unique_id_field: strother_field: str@app.get("/details")defdetails(unique_identifier_arg: str) ->MyDetails:
adapter=SPARQLModelAdapter(
target="https://graphdb.r11.eu/repositories/RELEVEN",
query="""SELECT ?unique_id_field ?other_field WHERE { VALUES (?unique_id_field ?other_field) { ('what' 'ever') ('other' 'ever')}""",
model=Details,
)
# single field filterreturnadapter.query_one(unique_id_field=unique_identifier_arg)
# or as a dict?#return adapter.query_one({ "unique_id_field": unique_identifier_arg })
SPARQLModelAdapter.query
currently only returns anrdfproxy.Page
instance, with models assigned to theitems
field.This roughly corresponds to a
ListView
in e.g. Django's Generic Display Views, so a respectiveDetailView
would be an interesting feature to have.The text was updated successfully, but these errors were encountered: