Class: Janus::QueryDirector

Inherits:
Object
  • Object
show all
Defined in:
lib/janus-ar/query_director.rb

Constant Summary collapse

ALL =
:all
REPLICA =
:replica
PRIMARY =
:primary
SQL_PRIMARY_MATCHERS =
[
  /\A\s*select.+for update\Z/i, /select.+lock in share mode\Z/i,
  /\A\s*select.+(nextval|currval|lastval|get_lock|release_lock|pg_advisory_lock|pg_advisory_unlock)\(/i,
  /\A\s*show/i
].freeze
SQL_REPLICA_MATCHERS =
[/\A\s*(select|with.+\)\s*select)\s/i].freeze
SQL_ALL_MATCHERS =
[/\A\s*set\s/i].freeze
SQL_SKIP_ALL_MATCHERS =
[/\A\s*set\s+local\s/i].freeze
WRITE_PREFIXES =
%w(INSERT UPDATE DELETE LOCK CREATE GRANT DROP ALTER TRUNCATE BEGIN SAVEPOINT FLUSH).freeze

Instance Method Summary collapse

Constructor Details

#initialize(sql, open_transactions) ⇒ QueryDirector

Returns a new instance of QueryDirector.



18
19
20
21
# File 'lib/janus-ar/query_director.rb', line 18

def initialize(sql, open_transactions)
  @_sql = sql
  @_open_transactions = open_transactions
end

Instance Method Details

#where_to_send?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
# File 'lib/janus-ar/query_director.rb', line 23

def where_to_send?
  if should_send_to_all?
    ALL
  elsif can_go_to_replica?
    REPLICA
  else
    PRIMARY
  end
end