Replies: 1 comment 2 replies
-
Sequel doesn't have anything built in that will do what you want. It sounds like what you want is probably best handled by a database trigger, assuming that whatever |
Beta Was this translation helpful? Give feedback.
-
Hi all,
First of all, a big thank you to all of you for all of your hard work maintaining Sequel, we’ve been using it at @affinity and it’s been awesome.
However, I’m writing in today in hopes of receiving some guidance on a bit of an unusual challenge we’re facing with Sequel.
Setup
We’re using Sequel 5.51.0, with Postgres 13.4.
Problem
We’re looking for a way to force writes on a set of table(s) to always go through a certain codepath. Basically, the way our app architecture is setup right now, we’d like to guarantee that every write to a set of table(s) performs another set of arbitrary side effects. Historically, we’ve used model hooks to try to enforce side effects in this manner, but as stated in the documentation, there are lots of ways to bypass this (via Datasets, etc.). At this point, we're looking for something with stronger guarantees than model hooks.
An Idea
Something we’re playing around with is implementing a plugin that overwrites all of the methods that perform writes, and forces them to use another class that we’ve written instead which will perform both the write (using Sequel normally) and any desired side effects. For example, the pseudocode would look something like this (please note, this isn't a working example, many details are left out):
A problem with the solution above is that some of these Sequel methods call other methods - for example the
create
ClassMethod
calls the thesave
InstanceMethod
, etc. For these "internal" Sequel calls, we'd like to preserve the original behavior (i.e. just callsuper
). Detecting these "internal" Sequel calls without modifying a ton of Sequel code is proving to be a little unwieldy and challenging.So, the question is - what is the best way, using Sequel, to guarantee that all writes to a set of table(s) go through a single codepath?
Has this been done before? Is there anything existing in the Sequel ecosystem that tries to tackle this problem? Appreciate any and all thoughts!
Beta Was this translation helpful? Give feedback.
All reactions