<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Dave Dash</title>
 <link href="http://davedash.com/tag/database/atom.xml" rel="self"/>
 <link href="http://davedash.com/tag/database"/>
 <updated>2012-04-07T22:42:44-07:00</updated>
 <id>http://davedash.com/</id>
 <author>
   <name>Dave Dash</name>
   <email>dd+atom1@davedash.com</email>
 </author>

 
 <entry>
   <title>Database versus files for Images</title>
   <link href="http://davedash.com/2009/02/18/database-versus-files-for-images/"/>
   <updated>2009-02-18T00:00:00-08:00</updated>
   <id>http://davedash.com/2009/02/18/database-versus-files-for-images</id>
   <content type="html">&lt;p&gt;This is a dead topic for sure, but one of the bad web development habits I had picked up was that storing everything in a database made things easier.&lt;/p&gt;

&lt;p&gt;I actually put some effort into thinking this through.  For me it was a case of management.  I didn't want to have to worry about two data stores for application-generated data.  In otherwords, the data in the database was all generated via my web application (either by myself or others who worked on the product, or by end users).  Having to also remember that there were select files as well seemed like a disaster.&lt;/p&gt;

&lt;p&gt;Most frameworks, correctly assume you'll upload files to a filesystem.  I never fully understood this until I thought about how I'd speed things up when the time comes to speed things up.  Django forces you to think that way.&lt;/p&gt;

&lt;p&gt;Almost from the start Django encourages you to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Upload any binary content to the filesystem with pointers in a database&lt;/li&gt;
&lt;li&gt;Have a separate server, or even machine serve static content.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Furthermore in a cached environment or even an environment that utilizes a CDN, putting static content in one spot, including user-generated content, was a big win.&lt;/p&gt;

&lt;p&gt;I've been porting an app from symfony to django for some time, and I had been serving images via the database.  Immediately when I switched to the filesystem I saw a huge benefit.  Not just a drop in database connections, but overall &quot;zippiness&quot; in the site.&lt;/p&gt;

&lt;p&gt;We'll see how well this performs in the real world, but I am quite sure that I learned my lesson.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Better than ORM Object Persistence</title>
   <link href="http://davedash.com/2007/12/20/better-than-orm-object-persistence/"/>
   <updated>2007-12-20T00:00:00-08:00</updated>
   <id>http://davedash.com/2007/12/20/better-than-orm-object-persistence</id>
   <content type="html">&lt;p&gt; After talking to people about the benefits and disadvantages of various ORMs... and reading up a little on non RDMBSs like &lt;a href=&quot;http://www.amazon.com/gp/browse.html?node=342335011&quot;&gt;Amazon SimpleDB&lt;/a&gt; I came to the realization that ORM is really a hack to get RDBMSs to work as a storage for objects.&lt;/p&gt;

&lt;p&gt;I'm being liberal with the term hack.  It really does work for a lot of situations, but it's not very elegant.  The workflow is more or less this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You create a database.&lt;/li&gt;
&lt;li&gt;You create some objects&lt;/li&gt;
&lt;li&gt;You define tables to store attributes of objects&lt;/li&gt;
&lt;li&gt;You establish a mapping&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;There's a lot that goes into database definition.  It would be nice to breakout from this line of thinking and do things a bit differently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create database&lt;/li&gt;
&lt;li&gt;Save named (e.g. Person, Place, Log, Restaurant, Rating, Review) serialized objects to the database.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Let the database learn from the saving of the object how to define the type.  In fact, it should be flexible and let us have mixmatched types, etc.&lt;/p&gt;

&lt;p&gt;Let the database index everything, and keep the indexes up to date, but prioritize it based on usage.  In other words if we usually query a database of Persons in order by a field called lastname, then make sure that index on lastname is always at hand.  We should be able to query this data back out of storage based on how we stored it.&lt;/p&gt;

&lt;p&gt;We should also be able to reach other objects in the database in a similar manner.&lt;/p&gt;

&lt;p&gt;The key here is letting the database layer do the heavy-thinking about what to do with serialized data, versus having some middle layer take care of it.&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;so I might just be naive about data and databases.  But if this idea is worthwhile and some database people can validate me, I'd be willing to work on it.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>doctine and getState()</title>
   <link href="http://davedash.com/2007/07/10/doctine-and-getstate/"/>
   <updated>2007-07-10T00:00:00-07:00</updated>
   <id>http://davedash.com/2007/07/10/doctine-and-getstate</id>
   <content type="html">&lt;p&gt;[tags]doctrine, php, symfony, sfDoctrine, database,errors[/tags]&lt;/p&gt;

&lt;p&gt;I tend to have models with a field called &lt;code&gt;state&lt;/code&gt;.  Doctrine offers a few ways of getting to the &lt;code&gt;state&lt;/code&gt; field:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$obj-&amp;gt;get('state');
$obj['state'];
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;$obj-&amp;gt;getState()&lt;/code&gt; however conflicts with &lt;code&gt;Doctrine_Record::getState()&lt;/code&gt; from which all objects inherit.  Use one of the above alternatives.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Saving a file to a database using symfony and doctrine</title>
   <link href="http://davedash.com/2007/07/07/saving-a-file-to-a-database-using-symfony-and-doctrine/"/>
   <updated>2007-07-07T00:00:00-07:00</updated>
   <id>http://davedash.com/2007/07/07/saving-a-file-to-a-database-using-symfony-and-doctrine</id>
   <content type="html">&lt;p&gt;[tags]symfony, doctrine, database, uploads, wordpress, fixme[/tags]&lt;/p&gt;

&lt;p&gt;I like to save content uploaded by website visitors to a database versus the file system.  It makes it easy having the data all in one spot.&lt;/p&gt;

&lt;p&gt;I tend to overcomplicate this process, so I wanted to write down the important steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In the template set &lt;code&gt;multipart=true&lt;/code&gt; for the form.  If you're using symfony helpers you can do this via:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; form_tag('@action', 'multipart=true')
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Extract the binary data you want to store in the database in your action:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; $path = $this-&amp;gt;getRequest()-&amp;gt;getFilePath('my_file');
 $size = $this-&amp;gt;getRequest()-&amp;gt;getFileSize('my_file');
 $type = $this-&amp;gt;getRequest()-&amp;gt;getFileType('my_file');    
 $data = fread(f_open($path, &quot;r&quot;), $size);

 $myObject              = new MyObject();
 $myObject['file_data'] = $data;
 $myObject['file_size'] = $size;
 $myObject['mime_type'] = $type;
 $myObject-&amp;gt;save();
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Wordpress is garbage so f_open should not have an underscore... what to do...&lt;/p&gt;

&lt;p&gt;At least that's how we role with Doctrine.  Note, Doctrine syntax is changing, and this may not be the most efficient way to create a new &lt;code&gt;Doctrine Record&lt;/code&gt; in your application.&lt;/p&gt;
</content>
 </entry>
 

</feed>

