Re 3) DataMapper and DataObjects maintain distinct connection logic, so as DataMapper opens and closes connections, that is distinct from the connection pooling which DataObjects performs. So there's no extra connection construction/teardown when DataMapper reconnects to DataObjects (which maintains the connection to dbs).
-T On Thu, May 5, 2011 at 7:02 AM, Chris Corbyn <[email protected]> wrote: > Hi, > > I hope you don't mind my asking here but I have a few questions about > something I'm doing. > > The MySQL adapter sets sql_mode in MySQL to an extremely strict set of > options, somewhere at a low level beyond the adapter's control. The > solution is to "undo" that change by setting a less strict mode. The > only way I could see to make this application-wide was to redefine the > #open_connection method. > > =begin > DataMapper Mixin to force sql_mode to allow our lack of use of default > values > > This can go away eventually, when we migrate out our incompatible > fields in MySQL. > =end > module Flippa > module DataMapper > > class ::DataMapper::Adapters::MysqlAdapter > def open_connection > connection = super > > statement = "SET sql_mode = ?" > bind_values = > [Flippa::Application.config.data_mapper_sql_mode] > command = > connection.create_command(statement) > command.execute_non_query(*bind_values) > > puts "Sending SET sql_mode" # DEBUG!! > > connection > end > end > > end > end > > Just a few questions (excuse my Rails newbiness): > > 1. I'm including this by putting a file in initializers called > data_mapper.rb, which simply has a require line for my module. Is > this the right place to do this? > 2. Is it weird that I've put the file at flippa/data_mapper, when in > fact the file only exists to decorate the MysqlAdapter class? It > feels weird, but maybe I'm just not so open minded with what I'm > doing, being new to Ruby. > 3. It looks like a connection is opened and closed for every single > query executed. Is this right? Isn't that expensive? > > If I knew how to do it I'd contribute back any changes I make to > improve support, by creating a plugin or whatever. This is a pretty > simple modification though ;) > > Cheers, > > Chris > > PS: Absolutely loving DataMapper. I'm seriously in awe of the > elegance of it all. It makes every other ORM I've worked with in the > past (and I've worked with a few) look pitiful ;) Kudos to you guys. > > -- > You received this message because you are subscribed to the Google Groups > "DataMapper" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/datamapper?hl=en. > > -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
