rails-sqlserver / activerecord-sqlserver-adapter

SQL Server Adapter For Rails
MIT License
974 stars 563 forks source link

Updated sample code for connection configuration #1242

Closed aidanharan closed 1 month ago

aidanharan commented 1 month ago

Custom connection configuration can now be performed by overriding the additional_connection_configuration method. Previous method as documented did not work.

Addresses issue raised by https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/1241

andsip commented 1 month ago

Thanks for the quick response and PR @aidanharan.

I can confirm that your proposed change restores the behavior that existed prior to 4842d2e884346.

There is a use case though which I have, that cannot be solved by this. That is, I need to adjust the DATEFORMAT setting like so:

@raw_connection.execute("SET DATEFORMAT 'dmy'").do

Since this setting potentially influences the setup in initialize_dateformatter, I would need this setting to be run before initialize_dateformatter. But with additional_connection_configuration at the end, it will run after. But we also cannot put this method before in general, as e.g. for the TEXTSIZE setting, it needs to be run after.

That's why I proposed the approach using #prepend in #1241, as with this, the user has more flexibility by calling super before or after the configuration settings. But maybe there are concerns about using this approach, which I am not aware of.

aidanharan commented 1 month ago

Yeah, your approach is better as it gives the user more flexibility as you say. I've updated the README with your code.