first implementation of Datalog.Query (not efficient yet)