-
Notifications
You must be signed in to change notification settings - Fork 577
Closed
Labels

Description
Hey,
I'd be very interested to know if people have already considered creating a query builder API?
I think it would help adoption if there was a convenient way to programatically build queries from within python in a LINQ kinda way.
Having such a DSL would not only allow for quicker generation of non prepared queries, as the entire parsing step would be omitted, it could also provide better tool support, as IDE's like pycharm would be capable of autocompleting and type checking queries.
I'd imagine something in the style of.
graph = rdflib.Graph()
query = SELECT(
v.s.AS(v.middle_aged_friend)
).WHERE(
(v.person, FOAF.knows, v.s),
(v.person, FOAF.age, v.age),
FILTER(l(35) < v.age)
FILTER(v.age < l(65))
)
tim = r("http://www.w3.org/People/Berners-Lee/card#i")
result = g.query(q , initBindings={'person': tim})
Which could further be simplified to the following, due to the first class nature of queries and their components.
graph = rdflib.Graph()
tim = r("http://www.w3.org/People/Berners-Lee/card#i")
query = SELECT(
v.s.AS(v.middle_aged_friend)
).WHERE(
(tim, FOAF.knows, v.s),
(tim, FOAF.age, v.age),
FILTER(l(35) < v.age)
FILTER(v.age < l(65))
)
result = g.query(q)
I'd be more than happy to start working on this 😄.
Thoughts, suggestions, comments?
iddan, magdasalatka and nsbgn