Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Middleware to include the response from the database #126

Closed
mvgijssel opened this issue Aug 6, 2019 · 0 comments · Fixed by #128
Closed

Extend Middleware to include the response from the database #126

mvgijssel opened this issue Aug 6, 2019 · 0 comments · Fixed by #128
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@mvgijssel
Copy link
Collaborator

mvgijssel commented Aug 6, 2019

#119 needs to have access to the response of the SQL query, so it knows which rows are affected for a subscription.

Currently an Arel ast is passed in to a middleware class as an argument and the return value is the argument for the next middleware. This needs a way call the next middleware from within the middleware to be able to get access to the response.

Rack and Express both have patterns to do this. Express passed the next middleware as an argument while Rack sets the next middleware in an initialiser. Passing the next middleware as an argument has the benefit that the classes can be stateless:

class Middleware
  def self.call(arel, next_middleware, context)
    updated_arel = arel.query(class: Arel::Table).each { ... }
    next_middleware.call(updated_arel)
  end
end

Here the next.call will call the next item in the middleware. The return value of this call will contain the actual response of the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant