module Sequel::QueryBlocker

  1. lib/sequel/extensions/query_blocker.rb

Public Class methods

extended(db)
[show source]
   # File lib/sequel/extensions/query_blocker.rb
65 def self.extended(db)
66   db.instance_exec do
67     @blocked_query_scopes ||= {}
68   end
69 end

Public Instance methods

allow_queries(opts=OPTS, &block)

Allow queries inside the block. Only useful if they are already blocked for the same scope. Useful for blocking queries generally, and only allowing them in specific places. Takes the same :scope option as block_queries.

[show source]
    # File lib/sequel/extensions/query_blocker.rb
105 def allow_queries(opts=OPTS, &block)
106   _allow_or_block_queries(false, opts, &block)
107 end
block_queries(opts=OPTS, &block)

Reject (raise an BlockedQuery exception) if there is an attempt to execute a query/statement inside the block.

The :scope option indicates which queries are rejected inside the block:

:global

This is the default, and rejects all queries.

:thread

Reject all queries in the current thread.

:fiber

Reject all queries in the current fiber.

Thread

Reject all queries in the given thread.

Fiber

Reject all queries in the given fiber.

[show source]
    # File lib/sequel/extensions/query_blocker.rb
119 def block_queries(opts=OPTS, &block)
120   _allow_or_block_queries(true, opts, &block)
121 end
block_queries?()

Whether queries are currently blocked.

[show source]
    # File lib/sequel/extensions/query_blocker.rb
 93 def block_queries?
 94   b = @blocked_query_scopes
 95   b.fetch(Fiber.current) do
 96     b.fetch(Thread.current) do
 97       b.fetch(:global, false)
 98     end
 99   end
100 end
log_connection_yield(sql, conn, args=nil)

Check whether queries are blocked before executing them.

[show source]
   # File lib/sequel/extensions/query_blocker.rb
83 def log_connection_yield(sql, conn, args=nil)
84   # All database adapters should be calling this method around
85   # query execution (otherwise the queries would not get logged),
86   # ensuring the blocking is checked.  Any database adapter issuing
87   # a query without calling this method is considered buggy.
88   check_blocked_queries!
89   super
90 end
valid_connection?(conn)

If checking a connection for validity, and a BlockedQuery exception is raised, treat it as a valid connection. You cannot check whether the connection is valid without issuing a query, and if queries are blocked, you need to assume it is valid or assume it is not. Since it most cases it will be valid, this assumes validity.

[show source]
   # File lib/sequel/extensions/query_blocker.rb
76 def valid_connection?(conn)
77   super
78 rescue BlockedQuery
79   true
80 end