After doing a bit of research, I had been amazed using the energy of Prolog to convey queries in an exceedingly simple way, similar to telling the equipment vocally how to proceed. This happened because I have become really tired of Propel and PHP at the office.

So, I have been wondering if there's a method to translate database table rows (Postgres, for instance) into Prolog details. This way, I possibly could stop using a lot of boring joins and taking advantage of ORM, and rather write something similar to this to obtain things i want:

mantenedora_ies(ID_MANTENEDORA, ID_IES) :- 
  papel_pessoa(ID_PAPEL_MANTENEDORA, ID_MANTENEDORA, 1),
  papel_pessoa(ID_PAPEL_IES, ID_IES, 6),
  relacionamento_pessoa(_, ID_PAPEL_IES, ID_PAPEL_MANTENEDORA, 3).

To determine why I have lose interest, take a look at this post. The code there'd be changed of these simple lines ahead, much simpler to see and understand. I am just interested in that, since it will likely be impossible to exchange things around here.

It might be also awesome if something of that nature was easy to be completed in PHP. Does anybody know something of that nature?

look into the ODBC interface of swi-prolog (maybe there's something equivalent for other prolog implementations too)

http://www.swi-prolog.org/pldoc/doc_for?object=section%280,%270%27,swi%28%27/doc/packages/odbc.html%27%29%29

There's the Draxler Prolog to SQL compiler, that translates some pattern (such as the conjunction you authored) in to the more verbose SQL joins. You'll find within the related publish (prolog to SQL converter) more information.

But beware that Prolog has its own weakness too, especially regarding aggregates. With no library, getting sums, counts and so on is not so easy. And the like libraries aren't so common, and simple to use.

I believe you could attempt to specialize the PHP DB interface for equijoins, while using builtin features that enables to shorten the query text (if this leads to more readable code). Employed in SWI-Prolog / ODBC, where (as with PHP) you have to compose SQL, I effettively found myself working this way, to deal with something much like that which you have proven within the other publish.

Another approach I discovered helpful: I authored a parser for that subset of SQL utilized by MySQL backup interface (PHPMyAdmin, really). So routinely I dump in your area my CMS' DB, load it memory, apply whathever duty task I want, computing and writing (or using) the place/update/remove claims, then upload these. You can do this because of the limited size the DB, that matches in memory. I have developed and today I am mantaining this small e-commerce with this particular naive approach.

Writing Prolog from PHP ought to be little difficult: I'd attempt to modify a current interface, such as the awesome Adminer, that already provides a choice among fundamental serialization formats.

I'm able to think about a couple of methods to this -

  1. On initialization, call a technique that works a chooses all data from the table and claims it in to the db. Do that for every db. You will have to declare the form of every row as :- dynamic ies_row/4 etc

  2. You can modify load_files by overriding user:prolog_load_files. Out of this activity you can so something such as #1. It has the advantage of searching just like a load_files call. http://www.swi-prolog.org/pldoc/man?predicate=prolog_load_file%2F2 ... This documentation mentions library(http_load), however i cannot find this anywhere (I had been thinking about this lately)!