77

Click here to load reader

Mura ORM & Ember JS

Embed Size (px)

DESCRIPTION

Originally presented by Matt Levine at MuraCon EU 2014 in Edinburgh, Scotland.

Citation preview

Page 1: Mura ORM & Ember JS

Mura ORM and EmberJS• By Matt Levine

Page 2: Mura ORM & Ember JS

Who Am I?

Page 3: Mura ORM & Ember JS

Who Am I?• CTO of Blue River Interactive Group

Page 4: Mura ORM & Ember JS

Who Am I?• CTO of Blue River Interactive Group• Started Mura CMS with Sean Schoeder a long time

ago...

Page 5: Mura ORM & Ember JS

What We’re Talking About

Page 6: Mura ORM & Ember JS

What We’re Talking About• Mura ORM

Page 7: Mura ORM & Ember JS

What We’re Talking About• Mura ORM• EmberJS

Page 8: Mura ORM & Ember JS

What We’re Talking About• Mura ORM• EmberJS• But Mostly Mura ORM

Page 9: Mura ORM & Ember JS

Why Mura ORM?

Page 10: Mura ORM & Ember JS

Why Mura ORM?• It all started with creating the Mura approval chains.

Page 11: Mura ORM & Ember JS

Why Mura ORM?• It all started with creating the new Mura approval

chains.• Needed to create 5 new entities and didn’t want to

write a custom DAO for each one.

Page 12: Mura ORM & Ember JS

Started with 3 Options

Page 13: Mura ORM & Ember JS

Started with 3 Options• Custom DAOs

Page 14: Mura ORM & Ember JS

Custom DAOs• Too much work

Page 15: Mura ORM & Ember JS

Custom DAOs• Too much work• No code re-use

Page 16: Mura ORM & Ember JS

Started with 3 Options• Custom DAOs• Mura Class Extension Module

Page 17: Mura ORM & Ember JS

Mura Class Extension ModuleGREAT FOR:

• Targeting nodes for custom business logic

Page 18: Mura ORM & Ember JS

Mura Class Extension ModuleGREAT FOR:

• Targeting nodes for custom business logic• Rendering events

Page 19: Mura ORM & Ember JS

Mura Class Extension ModuleGREAT FOR:

• Targeting nodes for custom business logic• Rendering events• Data events

Page 20: Mura ORM & Ember JS

Mura Class Extension ModuleGREAT FOR:

• Targeting nodes for custom business logic• Rendering events• Data events• Adding custom values to be used within rendering and

data events

Page 21: Mura ORM & Ember JS

Mura Class Extension ModuleNOT AS GOOD FOR:

• Maintaining relationships between entities

Page 22: Mura ORM & Ember JS

Mura Class Extension ModuleNOT AS GOOD FOR:

• Maintaining relationships between entities• Really custom business logic

Page 23: Mura ORM & Ember JS

Mura Class Extension ModuleNOT AS GOOD FOR:

• Maintaining relationships between entities• Really custom business logic• Directly querying the database

Page 24: Mura ORM & Ember JS

Mura Class Extension ModuleRECAP:

• Only handles very simple entities

Page 25: Mura ORM & Ember JS

Mura Class Extension ModuleRECAP:

• Only handles very simple entities• Great for hooking attributes to existing Mura entities, but

bad for complicated logic.

Page 26: Mura ORM & Ember JS

Mura Class Extension ModuleRECAP:

• Only handles very simple entities• Great for hooking attributes to existing Mura entities, but

bad for complicated logic.• Want the data to be stored in flat tables.

Page 27: Mura ORM & Ember JS

Mura Class Extension ModuleRECAP:

• Only handles very simple entities• Great for hooking attributes to existing Mura entities, but

bad for complicated logic.• Want the data to be stored in flat tables.• Not the appropriate choice

Page 28: Mura ORM & Ember JS

Started with 3 Options• Custom DAOs• Mura Class Extension Module• CF based Hibernate ORM

Page 29: Mura ORM & Ember JS

CF Hibernate ORMGREAT FOR:•Easily defining entity properties

Page 30: Mura ORM & Ember JS

CF Hibernate ORMGREAT FOR:•Easily defining entity properties•CRUD operations

Page 31: Mura ORM & Ember JS

CF Hibernate ORMGREAT FOR:•Easily defining entity properties•CRUD operations•Managing relationships to other CF ORM entities

Page 32: Mura ORM & Ember JS

CF Hibernate ORMGREAT FOR:•Easily defining entity properties•CRUD operations•Managing relationships to other CF ORM entities•You just describe the entity with properties and start

using it!

Page 33: Mura ORM & Ember JS

CF Hibernate ORMNOT SO GOOD FOR:•Creating relationships to Mura core entites

Page 34: Mura ORM & Ember JS

CF Hibernate ORMNOT SO GOOD FOR:•Creating relationships to Mura core entites•Working with DI1

Page 35: Mura ORM & Ember JS

CF Hibernate ORMNOT SO GOOD FOR:•Creating relationships to Mura core entites•Working with DI1•Don’t want to deal with sharing hibernate sessions with

other application and plugins

Page 36: Mura ORM & Ember JS

CF Hibernate ORMNOT SO GOOD FOR:•Creating relationships to Mura core entites•Working with DI1•Don’t want to deal with sharing hibernate sessions with

other application and plugins• It just works, but when it doesn't... Good Luck

Page 37: Mura ORM & Ember JS

CF Hibernate ORMRECAP:•Love the concept!

Page 38: Mura ORM & Ember JS

CF Hibernate ORMRECAP:•Love the concept!•Seems like CF ORM would be a walled garden.

Page 39: Mura ORM & Ember JS

CF Hibernate ORMRECAP:•Love the concept!•Seems like CF ORM would be a walled garden.•Sharing a ORM session with other sub applications

sounds like a nightmare

Page 40: Mura ORM & Ember JS

CF Hibernate ORMRECAP:•Love the concept!•Seems like CF ORM would be a walled garden.•Sharing a ORM session with other sub applications

sounds like a nightmare• I would like the relationships to be based on DI1

BeanName or Alias rather than component path.

Page 41: Mura ORM & Ember JS

CF Hibernate ORMRECAP:•When things go wrong it really feels like a black box. You

get low level java error that don't neccesarilly easily map to what you did wrong in your CFML•CF ORM really seems to want you to forget about sql

and just go through it's black box. I like sql. I think is it's pretty darn cool

Page 42: Mura ORM & Ember JS

What if?

Page 43: Mura ORM & Ember JS

What if?• I roll my own that works exactly how Mura works!

Page 44: Mura ORM & Ember JS

I Could Make Them Accesible via $.getBean(entityName); and application.serviceFactory(entityName);Takes advantage of DI1 dependency injection

Page 45: Mura ORM & Ember JS

Have the Same Interactions• entity.loadBy()• entity.get{relateEntity}Iterator();• entity.get{relateEntity}Query();• entity.get{relateEntity}();• entity.getFeed();• entity.validate();• entity.getError();

Page 46: Mura ORM & Ember JS

Have the Same Interactions• entityFeed.addParam();• entityFeed.getQuery();• entityFeed.getIterator();

Page 47: Mura ORM & Ember JS

Have the Same Interactionsfeed=$.getBean(entityName).getFeed();feed.addParam(column=’mycolumn’,criteria=‘test’);iterator=feed.getIterator();!

<cfloop condition=”iterator.hasNext()”><cfoutput>#iterator.next().getMyColumn()#</cfoutput></cfloop>

Page 48: Mura ORM & Ember JS

Be Targetable By Mura Eventscomponent extends=”mura.cfobject”{

onBeforeMyEntitySave($){var bean=$.event(‘bean’);....

}}

Page 49: Mura ORM & Ember JS

They Could Also• Know how to bundle themselves• Play well with Mura content versioning• Have a more simple implementation than CF ORM

Page 50: Mura ORM & Ember JS

It could use the same component attributes

• entityName• table• datasource• discriminatorColumn• discriminatorValue

• orderby• readonly

Page 51: Mura ORM & Ember JS

With some new ones• bundleable• cacheName• dbtype• manageSchema• useTrash

Page 52: Mura ORM & Ember JS

It could use the same property attributes

• name• persistent• fieldtype• cfc• fkcolumn

• type• cascade• singularName• orderby• length

• default• ormType

!

!

Page 53: Mura ORM & Ember JS

With some new ones• dataType• nullable• required• validate• message

• regex• comparable

Page 54: Mura ORM & Ember JS

And a bunch attributes for validation

• minValue• maxValue• minLength• maxLength• minCollection

• maxCollection• minList• maxList• inList• method

• lte• lt• gte• gt• eq

• neq

Page 55: Mura ORM & Ember JS

It could also support CF ORM • preLoad();• postLoad();• preUpdate();• postUpdate();• preCreate();

• postCreate();• postInsert();• preDelete();• postDelete();

Page 56: Mura ORM & Ember JS

So that’s what we did

Page 57: Mura ORM & Ember JS

So that’s what we did• Now let’s actually see some code

Page 58: Mura ORM & Ember JS

EmberJS

Page 59: Mura ORM & Ember JS

EmberJS• A Framework for Creating Ambitious Web Applications

Page 60: Mura ORM & Ember JS

EmberJS• A Framework for Creating Ambitious Web Applications• A Client Side MVC Framework

Page 61: Mura ORM & Ember JS

EmberJS• A Framework for Creating Ambitious Web Applications• A Client Side MVC Framework• That’s opinionated in a good way

Page 62: Mura ORM & Ember JS

EmberJS• A Framework for Creating Ambitious Web Applications• A Client Side MVC Framework• That’s opinionated in a good way• So that your application is developed in a consistent

way which enables easier scalability

Page 63: Mura ORM & Ember JS

EmberJS• A Framework for Creating Ambitious Web Applications• A Client Side MVC Framework• That’s opinionated in a good way• So that your application is developed in a consistent

way which enables easier scalability• Utilizes Handlebars.js for easy templating

Page 64: Mura ORM & Ember JS

Handlebar.JS<div> <label>Name:</label> {{input type="text" value=name placeholder="Enter your name"}}</div><div class="text"><h1>My name is {{name}} and I want to learn Ember!</h1></div>

Page 65: Mura ORM & Ember JS

Ember-Data•A Data Persistence Library for Ember.js

Page 66: Mura ORM & Ember JS

Ember-Data•A Data Persistence Library for Ember.js•We’ve created a Mura ORM Adapter for Ember-Data

Page 67: Mura ORM & Ember JS

Ember-Data•A Data Persistence Library for Ember.js•We’ve created a Mura ORM Adapter for Ember-Data•Sooo…

Page 68: Mura ORM & Ember JS

Ember-Datacomponent extends="mura.bean.beanORM" entityName="widget" table="widgets" {property name="widgetid" fieldtype=“id";property name="name" type=“string"length="100" required=true message="The name attribute is required an must be.";

property name="options" singularname="option" fieldtype="one-to-many" cfc="option" cascade="delete"; }

Page 69: Mura ORM & Ember JS

Ember-DataApp.Widget = DS.Model.extend({ primaryKey: 'widgetid', widgetid: DS.attr(), siteid: DS.attr(), name: DS.attr(), options: DS.hasMany('Option',{async:true})});

Page 70: Mura ORM & Ember JS

Ember-Datacomponent extends="mura.bean.beanORM" entityName="option" table="widgetoptions" {property name="optionid" fieldtype="id";property name="name" type="string" length="100" required=true message="The name attribute is required an must be.";property name="widget" fieldtype="many-to-one" cfc="widget" fkcolumn="widgetid";}

Page 71: Mura ORM & Ember JS

Ember-DataApp.Option = DS.Model.extend({ primaryKey: 'optionid', optionid: DS.attr(), siteid: DS.attr(), name: DS.attr(), widgetid: DS.attr(), widget: DS.belongsTo('Widget',{async:true})});

Page 72: Mura ORM & Ember JS

Ember-DataApp.WidgetRoute = Ember.Route.extend({ model: function(params) { return this.store.find(‘Widget’,params.widgetid); }});

Page 73: Mura ORM & Ember JS

Ember-Data<script type="text/x-handlebars" id=“widget"><h3>{{name}} ({{options.length}})</h3>{{#if options.length}}<ul>{{#each option in options}} <li>{{option.name}}</li>{{/each}}</ul>{{/if}}</script>

Page 74: Mura ORM & Ember JS

Ember.js•We’re currently prototyping an Ember.js based front for Mura

Page 75: Mura ORM & Ember JS

Ember.js•We’re currently prototyping an Ember.js based front for Mura•It will allow Mura to run as a service

Page 76: Mura ORM & Ember JS

Ember.js•We’re currently prototyping an Ember.js based front for Mura•It will allow Mura to run as a service•This will allow Mura sites to be served locally on any web server without needing a servlet container.

Page 77: Mura ORM & Ember JS

Ember.js•We’re currently prototyping an Ember.js based front for Mura•It will allow Mura to run as a service•This will allow Mura sites to be served locally on any web server without needing a servlet container.•We feel at this point it’s a perfect fit