I'd like to implement some kind of "databases" in Prolog.
I've two ideas to model tables and row :
% First one
client('B069','Laurent','769, rue de la LALALA','LLN','A1',10000).
% Second one
data(client,'B069',name,'Laurent').
data(client,'B069',adress,'69, rue de la LALALA').
data(client,'B069',town,'LLN').
data(client,'B069',cat,'A1').
data(client,'B069',amount,10000).
With the two models I can for example make respectively a "SELECT ID FROM client WHERE amount > 0" for client with positive amount :
% First one
client1_positive(Client) :- findall(ID,(data(client,ID,compte,Amount),Amount>0),Client).
% Second one
client2_positive(Client) :- findall(ID,(client(ID,_,_,_,_,Amount),Amount>0),Client).
They both have the same output ;
?- client1_positive(Clients).
Client = ['B069'].
?- client2_positive(Clients).
Client = ['B069'].
But here is my problem, since I'm very new to Prolog I have absolutely no idea how I can make that dynamic, like "SELECT name FROM client WHERE ID = 'B069' ". I can implement a rule for this specific SQL query but I can't find a way to implement a more abstract rule so every query could be interpreted.
Is there a best pratice for how to model those kind of datas in Prolog ? And some ideas (not a detailed answer to my problem) on how to make a request more abstract in Prolog ?
Thanks a lot
findallprematurely. just rely on non-determinism/backtracking and dofindall(orbagoforsetof) as late as possible. this way your predicates/rules will compose automatically.findallis kind of like an early forced evaluation of a computation that is normally lazily backtracked.