All That Jazz An intro to Databases with JazzRecord ORM
A Little About JazzRecord - Library agnostic (originally a MooTools project)   - ORM inspired by ActiveRecord in Rails. Most behaviors directly portable.   - Current Platforms: - Gears - AIR - Titanium PR1 (and beta thanks to @jhaynie!)
Core Features - Finders - Validation - Association loading - Preloading - Post load   - Fixtures and Migrations
Creating Models - Basics var JazzLegend = new Model({ table: "jazz_legends", columns: { name: "text", primary_instrument: "text", years_active: "text" } });
Creating Models - Associations //new version of JazzLegend model JazzLegend = new JazzRecord.Model({ table: "jazz_legends", foreignKey: "jazz_legend_id", hasMany: {albums: "albums"}, columns: { name: "text", primary_instrument: "text", years_active: "text" } }); //associated model Album = new JazzRecord.Model({ table: "albums", belongsTo: {artist: "jazz_legends"}, columns: { title: "text", year: "text", jazz_legend_id: "number" } });
Finders and Record Data var miles = JazzLegend.findBy("name", "Miles"); var louis = JazzLegend.first(); var dizzy = JazzLegend.find(2); miles.primary_instrument //trumpet louis.years_active //1914-1971miles.name = "Miles Dewey Davis III"; miles.save();  
Finders and Record Data - Destroy dizzy.destroy(); //someone must've grown tired of Dizzy! Album.count(); //3 albums so far, all Miles Album.destroyAll(); //like that time you lost all your CDs// when your car was broken into... Album.count(); //0, no more Miles!!
Validations var Programmer = new JazzRecord.Model({ //... validate: { atSave: function() { this.validatesIsString("name",  "You must have a name!"); this.validatesIsFloat("income", "We will gladly pay you a null salary!"); } } }); - Callbacks run at time of create or save (or both) - Several built in validators (based on Rails') - Write your own
Validation Errors p = Programmer.newRecord({name: 42,      income: "spare change"});p.save(); //false p.errors.name ["You must have a name!"]p.errors.income ["We will gladly pay you null salary"]p.name = "Nick"; p.income = null;p.isValid() //true
Association Preloading, Postloading - Defaulted to 1 level deep - Can be overridden at global level or per query - Immediately associated records loaded automatically - Additional records loaded with call to  load(assocName)  var milesRecords = miles.albums; //all of Miles' albums milesRecords.length //3 milesRecords[0].titlemilesRecords[0].load("artist") //miles again
Autolinking miles.albums.push(     Album.newRecord({title: "made up ish",         year: 2009     }) );miles.save(); Any record objects pushed into a  hasMany  array or pushed directly onto a  hasOne/belongsTo  property will be auto linked on save of the base record object.
Auto Unlinking   miles.albums.pop() //so long, fake albummiles.save(); Any records that were previously associated/loaded which are removed become dissociated on save of base record object
Future of JazzRecord - Unavoidable Asynchronous - HTML5 Difficulties, deeply nested structures - Will open up webOS, iPhone, async in AIR/Titanium - Everything callback-based - Initial work in 1 or 2 weeks - no association preloading - No timetable for full preloading -  Need Contributors : coders, docs translators
Project:     www.jazzrecord.org groups.google.com/group/jazzrecord http://github.com/thynctank/jazzrecord/tree/master Me:     thynctank.com [email_address] thynctank (AIM/GTalk/IRC/etc)
JazzFusion BYOM (bring your own model)
Rails inspired, but dead simple Provide a series of controllers, view templates and helper code in a standard file structure and sit back to watch it work.   Initially targeting browsers, AIR, Titanium  Info on writing your own routing mechanism (remote templates, server-generated dynamic content) Info on writing your own view template parsers. Out of box will allow inline script tags + simple string substitution, and/or markdown
Some Nice Features AppController's features inherited across all Controller objects Automatic Hijax for forms/links, passing data to router Before/after filters for keeping code DRY
When? Maybe June. That Burning Question

All That Jazz

  • 1.
    All That JazzAn intro to Databases with JazzRecord ORM
  • 2.
    A Little AboutJazzRecord - Library agnostic (originally a MooTools project)   - ORM inspired by ActiveRecord in Rails. Most behaviors directly portable.   - Current Platforms: - Gears - AIR - Titanium PR1 (and beta thanks to @jhaynie!)
  • 3.
    Core Features -Finders - Validation - Association loading - Preloading - Post load   - Fixtures and Migrations
  • 4.
    Creating Models -Basics var JazzLegend = new Model({ table: "jazz_legends", columns: { name: "text", primary_instrument: "text", years_active: "text" } });
  • 5.
    Creating Models -Associations //new version of JazzLegend model JazzLegend = new JazzRecord.Model({ table: "jazz_legends", foreignKey: "jazz_legend_id", hasMany: {albums: "albums"}, columns: { name: "text", primary_instrument: "text", years_active: "text" } }); //associated model Album = new JazzRecord.Model({ table: "albums", belongsTo: {artist: "jazz_legends"}, columns: { title: "text", year: "text", jazz_legend_id: "number" } });
  • 6.
    Finders and RecordData var miles = JazzLegend.findBy("name", "Miles"); var louis = JazzLegend.first(); var dizzy = JazzLegend.find(2); miles.primary_instrument //trumpet louis.years_active //1914-1971miles.name = "Miles Dewey Davis III"; miles.save();  
  • 7.
    Finders and RecordData - Destroy dizzy.destroy(); //someone must've grown tired of Dizzy! Album.count(); //3 albums so far, all Miles Album.destroyAll(); //like that time you lost all your CDs// when your car was broken into... Album.count(); //0, no more Miles!!
  • 8.
    Validations var Programmer= new JazzRecord.Model({ //... validate: { atSave: function() { this.validatesIsString("name", "You must have a name!"); this.validatesIsFloat("income", "We will gladly pay you a null salary!"); } } }); - Callbacks run at time of create or save (or both) - Several built in validators (based on Rails') - Write your own
  • 9.
    Validation Errors p= Programmer.newRecord({name: 42,     income: "spare change"});p.save(); //false p.errors.name ["You must have a name!"]p.errors.income ["We will gladly pay you null salary"]p.name = "Nick"; p.income = null;p.isValid() //true
  • 10.
    Association Preloading, Postloading- Defaulted to 1 level deep - Can be overridden at global level or per query - Immediately associated records loaded automatically - Additional records loaded with call to load(assocName) var milesRecords = miles.albums; //all of Miles' albums milesRecords.length //3 milesRecords[0].titlemilesRecords[0].load("artist") //miles again
  • 11.
    Autolinking miles.albums.push(    Album.newRecord({title: "made up ish",         year: 2009     }) );miles.save(); Any record objects pushed into a hasMany array or pushed directly onto a hasOne/belongsTo property will be auto linked on save of the base record object.
  • 12.
    Auto Unlinking  miles.albums.pop() //so long, fake albummiles.save(); Any records that were previously associated/loaded which are removed become dissociated on save of base record object
  • 13.
    Future of JazzRecord- Unavoidable Asynchronous - HTML5 Difficulties, deeply nested structures - Will open up webOS, iPhone, async in AIR/Titanium - Everything callback-based - Initial work in 1 or 2 weeks - no association preloading - No timetable for full preloading - Need Contributors : coders, docs translators
  • 14.
    Project:   www.jazzrecord.org groups.google.com/group/jazzrecord http://github.com/thynctank/jazzrecord/tree/master Me:   thynctank.com [email_address] thynctank (AIM/GTalk/IRC/etc)
  • 15.
    JazzFusion BYOM (bringyour own model)
  • 16.
    Rails inspired, butdead simple Provide a series of controllers, view templates and helper code in a standard file structure and sit back to watch it work.   Initially targeting browsers, AIR, Titanium Info on writing your own routing mechanism (remote templates, server-generated dynamic content) Info on writing your own view template parsers. Out of box will allow inline script tags + simple string substitution, and/or markdown
  • 17.
    Some Nice FeaturesAppController's features inherited across all Controller objects Automatic Hijax for forms/links, passing data to router Before/after filters for keeping code DRY
  • 18.
    When? Maybe June.That Burning Question