I was reviewing multiple ORMs, Og, ActiveRecord, Class::DBI, DBIx::Class, et al, and I was wondering if anyone knows of a more a Postgres centric way of solving the problems that ORMs are supposed to solve.
The purpose of my investigation was to incorporate an ORM into an MVC. I like what rails did mutating the both of them into one. But, I think they choose the worst ORM to do so. I don't like the fact that I'm supposed to design in an app, and roll changes to a db. I would much rather design in the db, and have the application adapt. Any form of validation should first and foremost be present in the db, and secondly in the app. Is there any ORM in existence that supports deducing column/table constraints from utilities like the information_schema. I was thinking of taking on the task of redesigning an ORM. The first purpose of this post is to see if there a consensus on a non-crappy ORM in existence, and then to get critique on a few ideas I've had.
-
Firstly, the ORM should support Postgres to the best of its ability, I don't care about supporting other DBs, or the support for other DBs.
-
The ORM should deduce at the bare minimum the table relations, the columns and their data-types, the constraints, etc.
-
It should start off by converting the information_schema, itself into an internal instance, and allow plugins to further deduce from the database.
-
Some MVC web frameworks supports scaffolding on the view, this should be thought of ideologically as scaffolding on the model.
-
The structure of the files could/should be significant to the structure of the db.
-
foo/bar/baz should imply the database foo, the schema bar, the table baz.
-
setting the connect string in the file foo should set a dynamic scaffolding model for all schemas and tables in the db foo
-
`touch`ing foo/bar should disable the dynamic scaffolding for all schemas except bar.
-
`touch`ing foo/bar/baz should likewise, disable dynamic scaffolding for all tables in schema bar except foo/bar/baz
-
Instances of the models should not necessitate a query on the database, Foo::bar::baz.quuz = 5; should translate into 'update bar.baz set quuz = 5', in rails a select must first be performed.
These are just some ideas, of how I would design it, I have a script that assembles an array of objects for each database, containing arrays of schema objects, which contain arrays of table objects, which contain arrays of column objects, which store things like constraints etc. This seems like a good start, I might take it further if others like this idea.
As a side note indigo on freenod, pointed me to python's sqlalchemy, an ORM that appears to offer some functionality with the information_schema using an AutoLoad=True arguement.
http://www.sqlalchemy.org/docs/metadata.myt#metadata
So monks, any ideas, and what ORM comes closest to a feature set like this?
Evan Carroll
www.EvanCarroll.com
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.