Hi Jeremy,
I've tried to gather some thoughts on Twitter regarding the idea of using Rodauth in a Rails app, and some people who looked at the rodauth-rails README expressed concern with Sequel requiring a separate database connection. I'm not too happy about it either, as currently in rodauth-rails the Sequel connection needs to
play catch with ActiveRecord in order for things to work in different contexts.
I know the ability to reuse ActiveRecord's connection has been talked about before, but I wanted to talk about possible changes to Sequel that could me made to allow this. My idea was ship an "activerecord" adapter within rodauth-rails (or extract it into a gem), whose `Database#connect` would retrieve a raw connection object from ActiveRecord, and do any adapter-specific modifications needed that other Database#connect methods do, while for Postgres wrapping it in a `Sequel::Postgres::Adapter` class.
To make this work, I thought we could make Sequel::Postgres::Adapter delegate to the underlying PG::Connection object instead of a subclass, which would allow initializing it with ActiveRecord's PG::Connection object. I've made a raw
proof-of-concept, which uses ruby's DelegateClass to avoid using #method_missing to hopefully minimize the performance impact. If I ran the tests correctly, they seem to pass both without and with sequel_pg.
Now, this implementation should still be improved. For one, it should probably use class_eval instead of define_method for performance (so it probably shouldn't use DelegateClass, as that uses define_method). And it still needs to address postgres-pr compatibility.
But, putting these things aside, do you think this approach could work?
Kind regards,
Janko