Thanks Jeremy. I will definitely look into autoload, but I suspect the way we add extensions at startup to all models will make that not work.
On Saturday, April 8, 2023 at 11:34:13 PM UTC-4 Jeremy Evans wrote: > On Sat, Apr 8, 2023 at 2:01 AM [email protected] <[email protected]> > wrote: > >> I'll preface this question: We still have to work through upgrading >> deprecation warnings so we can upgrade to Sequel 5.0/Ruby 3 (we're on >> 4.49.0/2.7.3) >> >> The system I work on has numerous postgres databases it connects to (it's >> a bit of a monolith). We have servers that only use parts of the system, >> but we end up connecting to every database at startup. >> >> I'm wondering if there's a lazy way to load databases, where it doesn't >> make an attempt to connect until a "real" reason to do so is needed. We >> currently have code that does `Sequel.connect` for each of the db urls, the >> loads a default set of extensions. >> >> If there was a `lazy_connect` for example, everything would work exactly >> the same until a model was queried, etc. >> >> I looked through the `connect` documentation and couldn't really come up >> with a way to do it. >> >> I'm just wondering if it's even possible to do something like this. >> > > By design, Sequel does not support loading a model class without a > connection to the database. It's not impossible to do so, but there is no > support for it. > > So the best way to do want you want is via autoload. Have the models use > databases that you want to lazy loaded to be autoloaded. This will delay > the connection to the database until one of the related model constants is > referenced. > > Thanks, > Jeremy > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/835b38b8-0fee-43e9-b108-fd793e917423n%40googlegroups.com.
