Tuesday, February 24, 2009

Caesar: the Live Query handler

Ok, so I've started implementing Live Queries in Rails. This means I've started work on a Rails plugin named Casear. Caesar has two goals:
  1. Eliminate controllers
  2. Eliminate routes.rb
What I've realized is that Live Queries are basically SQL using a URL. This means that a system built using Live Queries will basically be using Rails as a database. Eventually I'm sure we'll need things equivalent to Stored Procedures, Functions, and Triggers, but not yet.

I went through a few stages thinking about how to get rid of the controllers & routes.rb. I'm not exactly sure how it'll be done yet, but I'm thinking what'll end up happening is this:
  • When the routes are drawn only four routes will be created for Live Queries one for each action: Create, Read, Update, & Delete. The only difference between the routes will be the HTTP verb. (:format will be an optional parameter to the base route and will not get it's own formatted_ method)
  • During an http request Rails will do it's standard recognition stuff. (Except the controller/action will be created as needed)
  • When a _url or _path method is called we'll have to do some magic. My thought now is that we check the requested model and see if it exists. If it does we create call the requested action on the appropriate controller (creating the controller/action if needed). My thought here is that people should be able to use either the singular or plural version of the model name is the _url or _path call (this may be a nice way to differentiate between single calls and batch invocations).
A couple notes:
  • A controller will not be created until the first time a request is made against a model (via http or the _url/_path methods). In addition, the actions on the controller are not created until needed either.
  • At some point I'd like to have a caching mechanism set up so that multiple requests of the same url will not actually hit the controller multiple times unless the data requested has changed.
It's looking to me like I'm going to need to dig into the Rails route recognition & generation code. I'm also gonna get a crash course in dynamic code generation!

No comments:

Post a Comment