| Class | Rddb::View |
| In: |
lib/rddb/view.rb
|
| Parent: | Object |
A view on the database. Views are used to express queries. Views use Ruby blocks to process the documents in the document store and produce responses. Views can be materialized to improve performance.
| name | [R] | Get the name of the view. |
Initialize the view instance with the given name and the block used to map the documents to the view result set.
Options:
# File lib/rddb/view.rb, line 16
16: def initialize(database, name, options={}, &block)
17: @database = database
18: @name = name
19: @map_with = block
20:
21: @materialization_store = options[:materialization_store] if options[:materialization_store]
22: @distributed = options[:distributed]
23: end
Return true if the view querying is distributed.
# File lib/rddb/view.rb, line 89
89: def distributed?
90: @distributed
91: end
Materialize the view
# File lib/rddb/view.rb, line 48
48: def materialize(document_store)
49: #puts "querying for materialization"
50: @materialized = do_query(document_store)
51: materialization_store.store(self)
52: end
Define a block that is used to determine if the view requires updating. This is only used when a view is materialized.
# File lib/rddb/view.rb, line 63
63: def materialize_if(&block)
64: @materialize_check = block
65: return self
66: end
Return true if the view is a materialized view.
# File lib/rddb/view.rb, line 74
74: def materialized?
75: !@materialize_check.nil?
76: end
Provide a block that is used to reduce the result set upon completion of the mapping.
# File lib/rddb/view.rb, line 56
56: def reduce_with(&block)
57: @reduce_with = block
58: return self
59: end
Indicate that materialization is required before responding to queries.
# File lib/rddb/view.rb, line 69
69: def require_materialization
70: @require_materialization = true
71: end
Return true if the view requires an update for the specified document.
# File lib/rddb/view.rb, line 79
79: def should_refresh?(document)
80: materialized? && @materialize_check.call(document)
81: end
Interal query
# File lib/rddb/view.rb, line 95
95: def do_query(document_store, args={})
96: # map
97: results = do_map(document_store, args)
98: # reduce (if necessary)
99: @reduce_with.nil? ? results : @reduce_with.call(results)
100: end