/// Tuesday, November 29
As I thought more about a data access layer for Gamba, my ever flickering idea light came on and the solution was right in front of me. One of the goals of Gamba is to use Boo for everything, configuration, templates and so on. Why not use the CodeInjection library to simplify data access?
No matter which data access library is used, the library has to be told via a metadata file what data is queried and how to map those results to objects. (The exception being code generators which may need as little info as a connection string.) With the magic of CodeInjection metadata files can be transformed into managed code. And thus the genesis of Boo Data Templates.
- Fields/Properties are checked at compile-time
- No performance hit for dynamic run-time mapping to classes
- Supports both plain and dynamic SQL queries as well as stored procs
- Code is cleaner. The code is not marked with a ton of attributes.
- Classes are not overwritten by a code generator.
- Less XML configuration!
- No runtime query language which most ORMs provide. It's nice to be able to query a result set.
- You have to write SQL queries. Most ORMs shield you from this.
Boo Data Templates
Here's the bird's eye view of Boo Data Templates:
Each template contains a query and possibly a map definition if the result of the query is to be mapped to properties of the class. The templates are injected into Person via the MixinDataTemplates attribute. As an example, the Person.SelectAll.bdt template contains this:
query: Select = "select person_name, person_gender from person" map: Name = person_name Gender = person_gender
The class which uses the template looks like this:
[MixinDataTemplates] class Person: [property(Name)] _name = "" [property(Gender)] _gender = "M"
After compilation, the class looks like this:
class Person: [property(Name)] _name = "" [property(Gender)] _gender = "M" def SelectAll() as (Person): people = ExecuteQuery(queryFromTemplate) for p in people: person = Person() person.Name = people['person_name'] person.Gender = people['person_gender'] def Find(key) as Person: ... def Update(): ...
Cameron Kenneth Knight (ckknight) is taking this idea forward. This will be a very nice data layer. More details will come as the library progresses.