You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Arel middleware and the enhanced AST, it's possible to create a mechanism which "listens" to changes being sent to the database before they are executed.
All UPDATE, INSERT and DELETE statements can be parsed to figure out which tables will be affected which in turn can be used to trigger callbacks interested in certain changes.
In code it could look something like this:
subscription=Arel::Subscription.new# The query "SELECT * FROM posts" listens to the posts table, as# changes to the posts table will result in a different outcome for the SQL.subscription.add("SELECT * FROM posts")do |result|
puts"The posts table updated"# The result variable contains the data from "SELECT * FROM posts"# after the change to the table has been made.putsresultendArel.middleware.apply([subscription])do# This statement will trigger the subscription in the middleware# because it will generate an INSERT statement for the posts table.Post.create!text: 'some content',title: 'Some catchy title'end
A setup like this probably means that the Arel middleware needs to have access to the result of the SQL statement it sends to the database, which means refactoring the way middleware currently works.
UPDATE, INSERT and DELETE in postgres have support for a RETURNING clause, which can be used to return the affected rows. It might also be possible to include the subscription SQL in that clause to make it a single SQL statement.
The text was updated successfully, but these errors were encountered:
Using Arel middleware and the enhanced AST, it's possible to create a mechanism which "listens" to changes being sent to the database before they are executed.
All
UPDATE
,INSERT
andDELETE
statements can be parsed to figure out which tables will be affected which in turn can be used to trigger callbacks interested in certain changes.In code it could look something like this:
A setup like this probably means that the Arel middleware needs to have access to the result of the SQL statement it sends to the database, which means refactoring the way middleware currently works.
UPDATE
,INSERT
andDELETE
in postgres have support for aRETURNING
clause, which can be used to return the affected rows. It might also be possible to include the subscription SQL in that clause to make it a single SQL statement.The text was updated successfully, but these errors were encountered: