<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Juan Benavides &#187; orm</title>
	<atom:link href="http://juanbenavides.info/tag/orm/feed/" rel="self" type="application/rss+xml" />
	<link>http://juanbenavides.info</link>
	<description>Anotaciones de un Geek</description>
	<lastBuildDate>Tue, 25 Oct 2011 05:08:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Autobahn: una abstracción para bases de datos</title>
		<link>http://juanbenavides.info/autobahn-una-abstraccion-para-bases-de-datos/2010/01/</link>
		<comments>http://juanbenavides.info/autobahn-una-abstraccion-para-bases-de-datos/2010/01/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 11:54:20 +0000</pubDate>
		<dc:creator>Juan Benavides</dc:creator>
				<category><![CDATA[Programación]]></category>
		<category><![CDATA[autobahn]]></category>
		<category><![CDATA[microbus]]></category>
		<category><![CDATA[orm]]></category>

		<guid isPermaLink="false">http://juanbenavides.info/?p=292</guid>
		<description><![CDATA[Un proyecto que ya tenía en mente desde hace un buen tiempo, era hacer un nano-framework. CakePHP es muy bueno, pero a veces es simplemente demasiado para lo que paga el cliente. El punto es que nunca llegué a nada concreto y Armando se me adelanto espectacularmente con Microbus :D Microbus es mucho mejor de [...]]]></description>
			<content:encoded><![CDATA[<p>Un proyecto que ya tenía en mente desde hace un buen tiempo, era hacer un nano-framework. <a href="http://cakephp.org/">CakePHP</a> es muy bueno, pero a veces es simplemente <strong>demasiado</strong> para lo que paga el cliente. El punto es que nunca llegué a nada concreto y <a href="http://dupermag.com/">Armando</a> se me adelanto espectacularmente con <a href="http://github.com/soska/microbus">Microbus</a> :D</p>
<p><a href="http://github.com/soska/microbus">Microbus</a> es mucho mejor de lo que yo tenía en mente, así que prefiero meterle mano a este que reescribir la rueda -como si no fuera suficiente. El único detalle es que le faltaba un modelo de base de datos. <a href="http://github.com/Linnk/Autobahn">Autobahn</a> fue el resultado que por algunas razones, no pude liberar antes. Falta mucho todavía, pero así es como funciona:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lib/autobahn.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$library</span> <span style="color: #339933;">=</span> Autobahn<span style="color: #339933;">::</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//	Classic SQL</span>
<span style="color: #000088;">$authors</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$library</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT Author.id, Author.firstname FROM authors Author'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
<span style="color: #666666; font-style: italic;">//	Find (like Select)</span>
<span style="color: #000088;">$book</span>	  <span style="color: #339933;">=</span> <span style="color: #000088;">$library</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findBooksById</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$books</span>	  <span style="color: #339933;">=</span> <span style="color: #000088;">$library</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAllBooks</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$favorites</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$library</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAllBooksById</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//	Insert</span>
<span style="color: #000088;">$newBook</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'author_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Frameworks for PHP'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$library</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertBooks</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newBook</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//	Update</span>
<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Frameworks for PHP 5'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$conditions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$library</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">updateBooks</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$values</span><span style="color: #339933;">,</span> <span style="color: #000088;">$conditions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//	Delete</span>
<span style="color: #000088;">$library</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteBooksById</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">11</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//	Show stats of all queries :) ... only for CLI mode, for now.</span>
<span style="color: #000088;">$library</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">showLogs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Lo que sigue es mejorar el generador de consultas, el cual está mal hecho y repartido entre el objeto que abstrae MySQL y el objeto abstracto administrador. Una parte del generador se hace en el objeto abstracto y eso está mal, según mi teoría. SQL debería ser un estándar universal -como el HTML/CSS, ja- pero en la práctica no lo es del todo, siempre hay mínimas diferencias y debo de cuidar este hecho.</p>
<p>Una vez hecho lo anterior, el siguiente paso es diseñar el modelo padre, del cual se van a instanciar los modelos creados para la aplicación. Aquí seré cuidadoso, porque podría cometer el error de crecer demasiado el código, cuando la idea es mantenerlo corto y simple. El objetivo a lograr sería que pudiera manejar la base de datos de la siguiente manera:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lib/autobahn.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'model/book.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$book</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Book<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">author_id</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Frameworks for PHP'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">showLogs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Entre algunas otras ideas por ahí que rondan mi cabeza, esto es más o menos el resultado final que me gustaría. Pero siempre con el propósito de hacerlo corto y simple, por eficiencia y portabilidad principalmente. Ojalá a alguien le sirva :)</p>
]]></content:encoded>
			<wfw:commentRss>http://juanbenavides.info/autobahn-una-abstraccion-para-bases-de-datos/2010/01/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

