Class: Readyset::Query::CachedQuery

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

Overview

Represents a query that is cached by ReadySet.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, text:, name: nil, always: nil, count: nil) ⇒ CachedQuery

Constructs a new ‘CachedQuery` from the given attributes.

constructed

Parameters:

  • attributes (Hash)

    the attributes from which the ‘CachedQuery` should be



48
49
50
51
52
53
54
# File 'lib/readyset/query/cached_query.rb', line 48

def initialize(id: nil, text:, name: nil, always: nil, count: nil)
  @id = id
  @text = text
  @name = name
  @always = always
  @count = count
end

Instance Attribute Details

#alwaysObject (readonly)

Returns the value of attribute always.



12
13
14
# File 'lib/readyset/query/cached_query.rb', line 12

def always
  @always
end

#countObject (readonly)

Returns the value of attribute count.



12
13
14
# File 'lib/readyset/query/cached_query.rb', line 12

def count
  @count
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/readyset/query/cached_query.rb', line 12

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/readyset/query/cached_query.rb', line 12

def name
  @name
end

#textObject (readonly)

Returns the value of attribute text.



12
13
14
# File 'lib/readyset/query/cached_query.rb', line 12

def text
  @text
end

Class Method Details

.allArray<CachedQuery>

Returns all of the queries currently cached on ReadySet by invoking the ‘SHOW CACHES` SQL extension on ReadySet.

Returns:



18
19
20
# File 'lib/readyset/query/cached_query.rb', line 18

def self.all
  super('SHOW CACHES')
end

.drop_all!void

This method returns an undefined value.

Drops all the caches that exist on ReadySet.



25
26
27
28
29
# File 'lib/readyset/query/cached_query.rb', line 25

def self.drop_all!
  Readyset.raw_query('DROP ALL CACHES')

  nil
end

.find(id) ⇒ CachedQuery

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

found

Parameters:

  • id (String)

    the ID of the query to be searched for

Returns:

Raises:



39
40
41
# File 'lib/readyset/query/cached_query.rb', line 39

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

Instance Method Details

#==(other) ⇒ Boolean

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

Parameters:

  • the (CachedQuery)

    query against which ‘self` should be compared

Returns:

  • (Boolean)


60
61
62
63
64
65
# File 'lib/readyset/query/cached_query.rb', line 60

def ==(other)
  id == other.id &&
    text == other.text &&
    name == other.name &&
    always == other.always
end

#always?Boolean

Returns false if the cached query supports falling back to the upstream database and true otherwise.

Returns:

  • (Boolean)


71
72
73
# File 'lib/readyset/query/cached_query.rb', line 71

def always?
  always
end

#drop!void

This method returns an undefined value.

Drops the cache associated with this query.



78
79
80
81
# File 'lib/readyset/query/cached_query.rb', line 78

def drop!
  Readyset.drop_cache!(name)
  ProxiedQuery.find(id)
end