How to get all data from the Persistency file?

My file contains:

created(1613613236.7477932).
assert(user_data('$1$vUXiHMJy$Lm.hRA6tApw0kJWJZugoJ/','mike@gmail.com','123',1)).
assert(user_data('$1$vUXiHMJy$Lm.hRA6tGeI0kJWJZugoJS','clay@gmail.com','123',1)).

So these are my users and I want to create a list of all users. I’ve tried do user_data(Id,Email,Password,Role), but it returns the first record only.

Quick guess here; did not try any of this.

Once a persistency file is loaded, the data (facts in this case) should be accessible as expected and I take it that is what you are doing based on the question.

This should work.

bagof(user_data(Id,Email,Password,Role),user_data(Id,Email,Password,Role),Users).

Now all of the facts are in the variable Users as a list.

See: Finding all Solutions to a Goal

HTH


EDIT

I have created a few topics on this site that talk about and demonstrate using library(persistency), the most complete and accurate example code can be found in this post.

I think I forgot to say that I want to make a list of users on my website, and I don’t get the idea how I can do this via bagof.

Do you mean like this: Html_write, DCG generators and backtracking - #2 by Boris

Or something completely different?

1 Like

Yes, exactly! I didn’t expect to see foreach in Prolog :slight_smile: Thank you

There are two distinct "foreach"es in SWI-Prolog :slight_smile:

2 Likes