AirDB Updates
A summary of the several improvements committed to AirDB in the last five weeks. 1. Support for has-many and belongs-to associations 1. Support for multiple associations for a given Modeler class. 1. More smarts and existence checks for automatic schema migration 1. Call-chaining for Associations e.g. post.author.comments.count 1. Miscellaneous fixes, improvements and optimizations
Highlights of the major new additions since I
wrote about the initial design.
The Migrator handles schema versioning, checking and automatic migrations.
public class Migrator implements IMigratable { public function Migrator(klass:Class, options:Object, directives:Array) { // setup table structures, prototype fields, existing schema DB.migrate(this); } // Supported migration directives // create a table after processing the provided function block public function createTable(block:Function):void { ..} // specify a column, if it does not exist, it is created. public function column(name:String, dataType:uint, options:Object = null):void {..} // make a join table to handle many-many associations with specified class public function joinTable(klass:Class):void { .. } // map a foreign key for belongs-to association public function belongsTo(klass:Class):void { .. } }
The Associator handles associations which are specified via class meta-data. The improvements under the hood make it easier to make associations between Modeler object instances. For example
// Use the record ID of the target to specify associations // Post has-many comments post.comments.push(3); // Chain the target for further calls // Post belongs-to author and Author has-many comments // Obtain field value of associated target var nm:String = post.author.name; // Make further associations on associated target post.author.comments.push(new Comment({title: 'hello there'}));
Join queries and foreign-key lookups are now a breeze with AirDB.