Class: Readyset::Query::ProxiedQuery
- Inherits:
-
Object
- Object
- Readyset::Query::ProxiedQuery
- 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
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#supported ⇒ Object
readonly
Returns the value of attribute supported.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
-
.all ⇒ Array<ProxiedQuery>
Returns all of the queries proxied by ReadySet that are not currently cached.
-
.cache_all_supported!(always: false) ⇒ Array<CachedQuery>
Creates a cache for every proxied query that is not already cached.
-
.drop_all! ⇒ Object
Clears the list of proxied queries on ReadySet.
-
.find(id) ⇒ ProxiedQuery
Returns the proxied query with the given query ID.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Checks two proxied queries for equality by comparing all of their attributes.
-
#cache!(name: nil, always: false) ⇒ CachedQuery
Creates a cache on ReadySet for this query.
-
#initialize(id:, text:, supported:, count:) ⇒ ProxiedQuery
constructor
Constructs a new ‘ProxiedQuery` from the given attributes.
Constructor Details
#initialize(id:, text:, supported:, count:) ⇒ ProxiedQuery
Constructs a new ‘ProxiedQuery` from the given attributes.
constructed
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
#count ⇒ Object (readonly)
Returns the value of attribute count.
20 21 22 |
# File 'lib/readyset/query/proxied_query.rb', line 20 def count @count end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
20 21 22 |
# File 'lib/readyset/query/proxied_query.rb', line 20 def id @id end |
#supported ⇒ Object (readonly)
Returns the value of attribute supported.
20 21 22 |
# File 'lib/readyset/query/proxied_query.rb', line 20 def supported @supported end |
#text ⇒ Object (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
.all ⇒ Array<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.
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
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
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.
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
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 |