Class: Readyset::Query::ProxiedQuery

Inherits:
Object
  • Object
show all
Extended by:
Queryable
Includes:
ActiveModel::AttributeMethods
Defined in:
lib/readyset/query/proxied_query.rb

Overview

Represents an uncached query that has been proxied by ReadySet.

Defined Under Namespace

Classes: UnsupportedError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, text:, supported:, count:) ⇒ ProxiedQuery

Constructs a new ‘ProxiedQuery` from the given attributes.

constructed

Parameters:

  • attributes (Hash)

    the attributes from which the ‘ProxiedQuery` should be



63
64
65
66
67
68
# File 'lib/readyset/query/proxied_query.rb', line 63

def initialize(id:, text:, supported:, count:)
  @id = id
  @text = text
  @supported = supported
  @count = count
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



20
21
22
# File 'lib/readyset/query/proxied_query.rb', line 20

def count
  @count
end

#idObject (readonly)

Returns the value of attribute id.



20
21
22
# File 'lib/readyset/query/proxied_query.rb', line 20

def id
  @id
end

#supportedObject (readonly)

Returns the value of attribute supported.



20
21
22
# File 'lib/readyset/query/proxied_query.rb', line 20

def supported
  @supported
end

#textObject (readonly)

Returns the value of attribute text.



20
21
22
# File 'lib/readyset/query/proxied_query.rb', line 20

def text
  @text
end

Class Method Details

.allArray<ProxiedQuery>

Returns all of the queries proxied by ReadySet that are not currently cached. This list is retrieved by invoking the ‘SHOW PROXIED QUERIES` SQL extension on ReadySet.

Returns:



26
27
28
# File 'lib/readyset/query/proxied_query.rb', line 26

def self.all
  super('SHOW PROXIED QUERIES')
end

.cache_all_supported!(always: false) ⇒ Array<CachedQuery>

Creates a cache for every proxied query that is not already cached.

to these caches will never fall back to the database

Parameters:

  • always (Boolean) (defaults to: false)

    whether the cache should always be used. if this is true, queries

Returns:

  • (Array<CachedQuery>)

    an array of the newly-created caches



35
36
37
38
39
# File 'lib/readyset/query/proxied_query.rb', line 35

def self.cache_all_supported!(always: false)
  all.
    select { |query| query.supported == :yes }.
    map { |query| query.cache!(always: always) }
end

.drop_all!Object

Clears the list of proxied queries on ReadySet.



42
43
44
# File 'lib/readyset/query/proxied_query.rb', line 42

def self.drop_all!
  Readyset.raw_query('DROP ALL PROXIED QUERIES')
end

.find(id) ⇒ ProxiedQuery

Returns the proxied query with the given query ID. The query is searched for by directly querying ReadySet. If a proxied query with the given ID doesn’t exist, this method raises a ‘Readyset::Query::NotFoundError`.

ID cannot be found

Parameters:

  • id (String)

    the ID of the query to be searched for

Returns:

Raises:



54
55
56
# File 'lib/readyset/query/proxied_query.rb', line 54

def self.find(id)
  super('SHOW PROXIED QUERIES WHERE query_id = ?', id)
end

Instance Method Details

#==(other) ⇒ Boolean

Checks two proxied queries for equality by comparing all of their attributes.

Parameters:

  • the (ProxiedQuery)

    query against which ‘self` should be compared

Returns:

  • (Boolean)


74
75
76
77
78
# File 'lib/readyset/query/proxied_query.rb', line 74

def ==(other)
  id == other.id &&
    text == other.text &&
    supported == other.supported
end

#cache!(name: nil, always: false) ⇒ CachedQuery

Creates a cache on ReadySet for this query.

to these caches will never fall back to the database unsupported query

Parameters:

  • name (String) (defaults to: nil)

    the name for the cache being created

  • always (Boolean) (defaults to: false)

    whether the cache should always be used. if this is true, queries

Returns:

Raises:



88
89
90
91
92
93
94
95
# File 'lib/readyset/query/proxied_query.rb', line 88

def cache!(name: nil, always: false)
  if supported == :unsupported
    raise UnsupportedError, id
  else
    Readyset.create_cache!(id: id, name: name, always: always)
    CachedQuery.find(id)
  end
end