Expert system (used for database access) vs. ORM
<p>I have recently discovered <a href="http://pyke.sourceforge.net" rel="nofollow">PyKE</a>, and noticed that one of the given examples of a potential use (actually, the use for which it was originally built) was to compile SELECT statements to query a database, and map the result to a dictionary. The author emphasizes that this is not an ORM.</p>

<p>From this, I have two sub-questions:</p>

<ol>
<li>How is that usage of PyKE (or another expert system capable of executing or emitting code or returning structured data for use by a calling program) not effectively an ORM?</li>
<li>In what circumstances would it be preferable to use an expert system (such as PyKE) to query a database, as opposed to a purpose-built ORM? I assume there must be some, given that PyKE was made for the purpose.</li>
</ol>

<h3>To your first question</h3>

<p>An ORM is a layer between your logic and data that maps one to the other. Relational DBs often don't store data the way your objects use that data, so ORMs aim to abstract away the mental gymnastics needed to write the SQL to transform the data from one representation to another. (imho, They tend not to do it well or efficiently)</p>

<p>For PyKE specifically, <a href="http://pyke.sourceforge.net/examples.html#sqlgen" rel="nofollow">one aspect</a> offers SELECT compilation, but not apparently CRUDing (CRUD: Create, Read, Update, Delete), which is the most important thing an ORM does.</p>

<h3>On the second question</h3>

<p>PyKE would be used for when you might need a knowledge engine (natural language data search, for instance). Then PyKE may know how to extract the data from the database in the most efficient way to complete its own goals.</p>

<p>An ORM, on the other hand, would be given the data that represents some object in your program, such as a purchase order from a website, and it would insert the object when the PO is created, get it out of the DB when a session is restored, alter the data as the user adds and removes items to the PO, and remove the PO if the purchase is completed or aborted (CRUD). </p>

<hr>

<p><strong>tldr</strong></p>

<p>PyKE is a specialized library that abstracts away some of the need to write SQL to use the library, but doesn't offer a complete set of DB interaction, because that's not what it was built for.</p>

<p>ORMs do offer this interaction with DBs, and attempt to make it easier to use data in a very dynamic way; though in my experience to use / not to use an ORM over hand crafted SQL sparks some pretty fierce debates.</p>

python orm language-agnostic expert-system pyke