From: Golemon, B. <Buc...@am...> - 2008-08-18 23:13:53
|
I'm considering using SQLObject for a new big project (and submitting patches to make the tests pass under mysql), but I want to convince myself that SQLObject would have worked for my old project first. I built my own quasi-ORM (before I knew that ORM's existed) that allowed a user to specify a filter on any column in the database, and the system would join it into the query. All that needed to be specified was the fields to query and a set of filters. The resulting query was something like this: SELECT DISTINCT flows.FlowSubTarget, MAX(projects.FCassy) AS MAX, projects.IsRelease FROM files, names, projects, flows, values_i WHERE names.MetricType = 'i' AND names.FlowId = flows.id AND projects.id = files.ProjectId AND projects.MaxMTime > DATE_SUB(NOW(), INTERVAL 10 DAY) AND flows.FlowSubTarget RLIKE BINARY '^Sort.*(Stp|Setup)' AND projects.Project = 'peach' AND files.id = values_i.FileId AND projects.FCassy >= 0 AND projects.Tapeout = 'sa15' AND values_i.NameId = names.id GROUP BY flows.FlowSubTarget, projects.IsRelease; Note that the query returns values from various tables. The most bothersome thing to me about ORM's is that they seem to only return data from one specific table at a time. The code that generated this query went something like the following. (Not exactly because parts were from configuration files and parts were from previous queries, making the whole thing dynamic). q = db.select("FlowSubTarget", alias(max("FCassy"), "MAX"), "IsRelease") q.filters( MetricType = 'i', Project = 'mario', Tapeout = 'sa11' ) q.add_filter(MaxMTime, ">", "DATE_SUB(NOW(), INTERVAL 10 DAY)") q.add_filter(FlowSubTarget, "RLIKE BINARY", "'^Sort.*(Stp|Setup)'") q.add_filter(FCassy, ">=", 0) q.group_by("FlowSubTarget", "IsRelease") print q I understand that automatic joining like this is not generally a good idea, but it's necessary in this case because the fields to filter are not known till run time. The result is deterministic because the database has no cycles (aka. tree topology). My question is: Could I have used SQLObject to do this (reasonably)? Thanks ahead of time for any light you can shed on this subject. --Buck -----Original Message----- From: sql...@li... [mailto:sql...@li...] On Behalf Of Sam's Lists Sent: Sunday, August 17, 2008 3:46 AM To: sqlobject-discuss Subject: [SQLObject] Having a modified column filled in automagically... Hi... I'd like to be able to create a timestamp column called "mtime" in some of my columns. This would hold a timestamp of when the row was last modified. But I'd like the timestamp to be updated automatically whenever sqlobject updates anything else in the row. How can I do this? I'd like a solution that is easy to add to any table....maybe so easy that the table only has to have a column called mtime and then everything happens without anything extra on my part. Thanks |