robmiller/ruby-wpdb — pull request #2 by robmiller (2013-09-13 17:54:16+00:00)
Title: GravityForms modelling

Modelling the GravityForms tables as-is is one thing, and should be relatively straightforward.

Another thing that would be good, though, would be to actually impose some order on them and minimise the ridiculous level of self-joins you have to do to actually work with data in the `lead_detail` table.

For example, if I had a form called "Contact Form" with the fields "Name", "Email", and "Message", I'd love to be able to create new records with:

WPDB::GravityForms::ContactForm.create(:name => 'Rob', :email => 'rob@example.com', :message => 'hello world')

or filter records with:

WPDB::GravityForms::ContactForm.where(:name => 'Rob').all

This might be beyond the realms of plausibility, though.

Potential trouble spots:

* Dynamically creating classes, dynamically creating accessor methods on those classes
* Extracting of names for fields (rather than numbers)
* Mapping properties (e.g. name, email) to field numbers, including accessors (`name=`, `email=`)
* Can Sequel even map to this abstract a datastore, or will we end up repeating all of the logic? (i.e. is it able to, by defining a model alone, translate `entry.name = 'foo'` to `INSERT INTO wp_rg_lead_detail (field_number, value) VALUES (3, 'foo')`? I'm guessing not…)