Pages

Saturday, March 31, 2012

Things your server needs in order to not suck

On the database side, you need full-text search, you need transactions, check constraints, and you probably need real schemas.

Full-Text search allows you to find records by similarity, which is what most users expect these days (thanks Google). Some moron will tell ya, "oh you can use Lucene or Sphinx". Too bad they don't really talk to databases eh? Ya, polling your database for modified records every minute is a great idea. Upon getting Lucene to sync with MySQL you will end up like Mel Gibson in this scene:

http://www.youtube.com/watch?v=UpOqkz86_lg#t=135s

And you need transactions and check constraints if you remotely care about the integrity of your data. If you don't, please continue to use MyISAM.

You need schemas (real ones, not MySQL ones) if you want a multi-tenant system that doesn't suck. If you only have one tenant, this doesn't apply. You can still do it with MySQL, but it provides much butt-hurt.

The above requirements rules out MySQL. UPDATE: MySQL 5.6.4 supports full-text search on InnoDB! Holy shit. Still no check constraints or schemas though. Use PostgreSQL.

On the application server side, you need a comprehensive validation library, deeply-nested JSON support, support for table inheritance, and concurrency control in your ORM.

By deeply nested JSON support I mean being able to load JSON from a POST into your models and into your database in a couple lines of code, with validation. With hasOne, hasMany, and manyMany relationships. You should also be able to write 50 records or so, with relations of arbitrary nesting depth, very fast.

By support for table inheritance, I mean this: http://martinfowler.com/eaaCatalog/singleTableInheritance.html , and the other schemes. Ruby's ActiveRecord supports STI, and PHP's Doctrine supports single and multi. Yii's ActiveRecord sorta-kinda-almost supports STI, but requires some work.

Concurrency means that your UPDATE will fail if you try to update a record that someone has updated since you read it. Usually this means a query like this:

UPDATE mytable SET (field1='happy' and field2='monday') where id=59 and (field1='sad' and field2='sunday')

Unfortunately, this is not built in to Yii, which I have been using. Yii's validation library is actually really good, but it sucks at nested JSON and it doesn't do concurrency. It looks like Doctrine ORM does concurrency, but has no validation for some bizarre reason. I might have to switch to Ruby, or hell, even go back to ASP.Net

Tuesday, February 14, 2012

How to disable change / validation events when using loadRecord

When you use Basic.loadRecord() to load a record into a form, all of the form fields fire their change events, which you might not want. Here's a quick way to fix this:

This prevents change events from firing, but then re-enables them:

var basic = form.getForm();

basic.getFields().each(function(item, index, length){
  item.suspendCheckChange++;
});

basic.loadRecord(myRecord);

basic.getFields().each(function(item, index, length){
  item.suspendCheckChange--;

}); 

How to prompt the user to save a dirty form if leaving the page

How to prompt the user to save a dirty form if leaving the page:

  1. set the Basic Form's trackResetOnLoad to true
  2. handle the form's dirtychange event

something like this:

function my_onbeforeunload(e){
  message = 'You have unsaved changes. Are you sure you want to leave this page?'; 
  e = e || window.event;
  if(e){
    e.returnValue = message;
  }
  return message;
}

form.on('dirtychange', function(basic, dirty, eOpts){
  window.onbeforeunload = dirty ? my_onbeforeunload : null; 
});

Tuesday, January 31, 2012

Sencha Designer 2 Beta is out

I am a big fan of Ext Designer 1.2. It saves a ton of time designing a UI. Doesn't help much with MVC or writing code though.

It has been re-branded as Sencha Designer 2 (due to Sencha touch integration), and has built-in code editing and MVC! The beta is out now.

You can try it here:

http://www.sencha.com/forum/showthread.php?152941-Sencha-Designer-2-Beta-Download-links

Sencha didn't link to the docs anywhere, but here they are:

http://docs.sencha.com/designer/2-0/