Class: WCC::Contentful::Store::PostgresStore::Query

Inherits:
Query
  • Object
show all
Defined in:
lib/wcc/contentful/store/postgres_store.rb

Constant Summary

Constants inherited from Query

Query::FALSE_VALUES, Query::RESERVED_NAMES

Constants included from Query::Interface

Query::Interface::OPERATORS

Instance Attribute Summary

Attributes inherited from Query

#conditions, #content_type, #store

Instance Method Summary collapse

Methods inherited from Query

#apply, #apply_operator, flatten_filter_hash, #initialize, known_locales, normalize_condition_path, op?, #to_enum

Methods included from Query::Interface

#apply, #eq

Constructor Details

This class inherits a constructor from WCC::Contentful::Store::Query

Instance Method Details

#countObject



165
166
167
168
169
170
171
# File 'lib/wcc/contentful/store/postgres_store.rb', line 165

def count
  return @count if @count

  statement, params = finalize_statement('SELECT count(*)')
  result = store.exec_query(statement, params)
  @count = result.getvalue(0, 0).to_i
end

#firstObject



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/wcc/contentful/store/postgres_store.rb', line 173

def first
  return @first if @first

  statement, params = finalize_statement('SELECT t.*', ' LIMIT 1', depth: @options[:include])
  result = store.exec_query(statement, params)
  return if result.num_tuples == 0

  row = result.first
  entry = JSON.parse(row['data'])

  if @options[:include] && @options[:include] > 0
    includes = decode_includes(row['includes'])
    entry = resolve_includes([entry, includes], @options[:include])
  end
  entry
end

#result_setObject



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/wcc/contentful/store/postgres_store.rb', line 190

def result_set
  return @result_set if @result_set

  statement, params = finalize_statement('SELECT t.*', depth: @options[:include])
  @result_set =
    store.exec_query(statement, params)
      .lazy.map do |row|
      entry = JSON.parse(row['data'])
      includes =
        (decode_includes(row['includes']) if @options[:include] && @options[:include] > 0)

      [entry, includes]
    end
rescue PG::ConnectionBad
  []
end