Class: Moped::Protocol::Query
- Includes:
- Message
- Defined in:
- lib/moped/protocol/query.rb
Overview
The Protocol class for querying a collection.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#collection ⇒ String, Symbol
readonly
The collection to query.
-
#database ⇒ String, Symbol
readonly
The database to query.
-
#fields ⇒ Hash?
The fields to include in the reply.
-
#flags ⇒ Array
The flags for the query.
-
#full_collection_name ⇒ String
The namespaced collection name.
-
#length ⇒ Number
The length of the message.
-
#limit ⇒ Number
The number of documents to return.
-
#op_code ⇒ Number
OP_QUERY operation code (2004).
-
#request_id ⇒ Number
The request id of the message.
-
#selector ⇒ Hash
The selector for this query.
-
#skip ⇒ Number
The number of documents to skip.
Instance Method Summary collapse
-
#initialize(database, collection, selector, options = {}) ⇒ Query
constructor
Create a new query command.
- #log_inspect ⇒ Object
-
#receive_replies(connection) ⇒ Protocol::Reply
Receive replies to the message.
Methods included from Message
included, #inspect, #serialize
Constructor Details
#initialize(database, collection, selector, options = {}) ⇒ Query
Create a new query command.
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/moped/protocol/query.rb', line 101 def initialize(database, collection, selector, = {}) @database = database @collection = collection @full_collection_name = "#{database}.#{collection}" @selector = selector @request_id = [:request_id] @flags = [:flags] @limit = [:limit] @skip = [:skip] @fields = [:fields] end |
Instance Attribute Details
#collection ⇒ String, Symbol (readonly)
Returns the collection to query.
79 80 81 |
# File 'lib/moped/protocol/query.rb', line 79 def collection @collection end |
#database ⇒ String, Symbol (readonly)
Returns the database to query.
76 77 78 |
# File 'lib/moped/protocol/query.rb', line 76 def database @database end |
#fields ⇒ Hash?
Returns the fields to include in the reply.
65 |
# File 'lib/moped/protocol/query.rb', line 65 document :fields, :optional => true |
#flags ⇒ Array
The flags for the query. Supported flags are: :tailable
, :slave_ok
, :no_cursor_timeout
, :await_data
, :exhaust
.
41 42 43 44 45 |
# File 'lib/moped/protocol/query.rb', line 41 flags :flags, tailable: 2 ** 1, slave_ok: 2 ** 2, no_cursor_timeout: 2 ** 4, await_data: 2 ** 5, exhaust: 2 ** 6 |
#full_collection_name ⇒ String
Returns the namespaced collection name.
49 |
# File 'lib/moped/protocol/query.rb', line 49 cstring :full_collection_name |
#length ⇒ Number
Returns the length of the message.
23 |
# File 'lib/moped/protocol/query.rb', line 23 int32 :length |
#limit ⇒ Number
Returns the number of documents to return.
57 |
# File 'lib/moped/protocol/query.rb', line 57 int32 :limit |
#op_code ⇒ Number
Returns OP_QUERY operation code (2004).
33 |
# File 'lib/moped/protocol/query.rb', line 33 int32 :op_code |
#request_id ⇒ Number
Returns the request id of the message.
27 |
# File 'lib/moped/protocol/query.rb', line 27 int32 :request_id |
#selector ⇒ Hash
Returns the selector for this query.
61 |
# File 'lib/moped/protocol/query.rb', line 61 document :selector |
#skip ⇒ Number
Returns the number of documents to skip.
53 |
# File 'lib/moped/protocol/query.rb', line 53 int32 :skip |
Instance Method Details
#log_inspect ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/moped/protocol/query.rb', line 114 def log_inspect type = "QUERY" fields = [] fields << ["%-12s", type] fields << ["database=%s", database] fields << ["collection=%s", collection] fields << ["selector=%s", selector.inspect] fields << ["flags=%s", flags.inspect] fields << ["limit=%s", limit.inspect] fields << ["skip=%s", skip.inspect] fields << ["fields=%s", self.fields.inspect] f, v = fields.transpose f.join(" ") % v end |
#receive_replies(connection) ⇒ Protocol::Reply
Receive replies to the message.
139 140 141 |
# File 'lib/moped/protocol/query.rb', line 139 def receive_replies(connection) connection.read end |