Skip to content
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

Implement DetailView feature #198

Open
lu-pl opened this issue Jan 21, 2025 · 2 comments
Open

Implement DetailView feature #198

lu-pl opened this issue Jan 21, 2025 · 2 comments
Assignees
Labels
enhancement New feature or request priority Needs urgent fix

Comments

@lu-pl
Copy link
Contributor

lu-pl commented Jan 21, 2025

SPARQLModelAdapter.query currently only returns an rdfproxy.Page instance, with models assigned to the items field.

This roughly corresponds to a ListView in e.g. Django's Generic Display Views, so a respective DetailView would be an interesting feature to have.

@lu-pl lu-pl added the enhancement New feature or request label Jan 21, 2025
@lu-pl lu-pl self-assigned this Feb 10, 2025
@lu-pl lu-pl added this to the v0.4.0 release milestone Feb 10, 2025
@kevinstadler
Copy link

Example of desired usage:

class MyDetails(BaseModel):
    unique_id_field: str
    other_field: str

@app.get("/details")
def details(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,
    )

    return adapter.query_one()

@kevinstadler kevinstadler added priority Needs urgent fix and removed discussion wanted labels Feb 10, 2025
@lu-pl lu-pl modified the milestones: v0.2.0 release, v0.4.0 release Feb 11, 2025
@kevinstadler
Copy link

kevinstadler commented Feb 12, 2025

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:

class MyDetails(BaseModel):
    unique_id_field: str
    other_field: str

@app.get("/details")
def details(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 filter
    return adapter.query_one(unique_id_field = unique_identifier_arg)
    # or as a dict?
    #return adapter.query_one({ "unique_id_field": unique_identifier_arg })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority Needs urgent fix
Projects
None yet
Development

No branches or pull requests

2 participants