@@ -57,34 +57,55 @@ def is_failed_with_node(self, node):
57
57
58
58
59
59
class GetDocumentCommand (RavenCommand ):
60
- def __init__ (self , key_or_keys , includes = None , metadata_only = False ):
60
+ def __init__ (self , key_or_keys , includes = None , metadata_only = False , start = None , page_size = None ,
61
+ counter_includes = None ):
61
62
"""
62
63
@param key_or_keys: the key of the documents you want to retrieve (key can be a list of ids)
63
64
:type str or list
64
65
@param includes: array of paths in documents in which server should look for a 'referenced' document
65
66
:type list
66
67
@param metadata_only: specifies if only document metadata should be returned
67
68
:type bool
69
+ @param start: number of results to skip.
70
+ type: int
71
+ @param page_size: maximum number of results to retrieve
72
+ type: int
73
+ @param counter_includes: the names of the counters to be included or True to include all counters
74
+ type: list[str] or bool
68
75
@return: A list of the id or ids we looked for (if they exists)
69
76
:rtype: dict
70
77
"""
71
78
super (GetDocumentCommand , self ).__init__ (method = "GET" , is_read_request = True )
72
79
self .key_or_keys = key_or_keys
73
80
self .includes = includes
74
81
self .metadata_only = metadata_only
82
+ self .start = start
83
+ self .page_size = page_size
84
+ self .counter_includes = counter_includes
75
85
76
- def create_request (self , server_node ):
77
86
if self .key_or_keys is None :
78
87
raise ValueError ("None Key is not valid" )
88
+
89
+ def create_request (self , server_node ):
79
90
path = "docs?"
91
+
92
+ if self .start :
93
+ path += f"&start={ self .start } "
94
+ if self .page_size :
95
+ path += f"&pageSize={ self .page_size } "
96
+ if self .metadata_only :
97
+ path += "&metadataOnly=true"
80
98
if self .includes :
81
99
path += "" .join ("&include=" + Utils .quote_key (item ) for item in self .includes )
100
+ if self .counter_includes :
101
+ if self .counter_includes is True :
102
+ path += f"&counter={ Utils .quote_key ('@all_counters' )} "
103
+ else :
104
+ path += "" .join ("&counter=" + Utils .quote_key (item ) for item in self .counter_includes )
105
+
82
106
# make get method handle a multi document requests in a single request
83
107
if isinstance (self .key_or_keys , list ):
84
108
key_or_keys = collections .OrderedDict .fromkeys (self .key_or_keys )
85
- if self .metadata_only :
86
- path += "&metadataOnly=true"
87
-
88
109
# If it is too big, we drop to POST (note that means that we can't use the HTTP cache any longer)
89
110
if (sum (len (x ) for x in key_or_keys )) > 1024 :
90
111
self .method = "POST"
@@ -111,6 +132,82 @@ def set_response(self, response):
111
132
return response
112
133
113
134
135
+ class GetDocumentsByPrefixCommand (RavenCommand ):
136
+ def __init__ (self , start_with , start_after = None , matches = None , exclude = None , start = None , page_size = None ,
137
+ metadata_only = None ):
138
+
139
+ """
140
+ @param start_with: Retrieve all documents whose IDs begin with this string.
141
+ If the value of this parameter is left empty, all documents in the database are retrieved.
142
+ :type str
143
+
144
+ @param start_after: Retrieve only the results after the first document ID that begins with this prefix.
145
+ :type str
146
+
147
+ @param matches: Retrieve documents whose IDs are exactly <startsWith>+<matches>.
148
+ Accepts multiple values separated by a pipe character: ' | ' .
149
+ Use ? to represent any single character, and * to represent any string.
150
+ :type str
151
+
152
+ @param exclude: Exclude documents whose IDs are exactly <startsWith>+<exclude>.
153
+ Accepts multiple values separated by a pipe character: ' | ' .
154
+ Use ? to represent any single character, and * to represent any string.
155
+ type: str
156
+
157
+ @param start: number of results to skip.
158
+ type: int
159
+
160
+ @param page_size: maximum number of results to retrieve
161
+ type: int
162
+
163
+ @param metadata_only: specifies if only document metadata should be returned
164
+ :type bool
165
+
166
+ @return: A list of the id or ids we looked for (if they exists)
167
+ :rtype: dict
168
+ """
169
+
170
+ super (GetDocumentsByPrefixCommand , self ).__init__ (method = "GET" , is_read_request = True )
171
+
172
+ self .start_with = start_with
173
+ self .start_after = start_after
174
+ self .matches = matches
175
+ self .exclude = exclude
176
+ self .start = start
177
+ self .page_size = page_size
178
+ self .metadata_only = metadata_only
179
+
180
+ if self .start_with is None :
181
+ raise ValueError ("None start_with is not valid" )
182
+
183
+ def create_request (self , server_node ):
184
+ path = f"docs?startsWith={ Utils .quote_key (self .start_with )} "
185
+
186
+ if self .matches :
187
+ path += f"&matches={ Utils .quote_key (self .matches )} "
188
+ if self .exclude :
189
+ path += f"&exclude={ Utils .quote_key (self .exclude )} "
190
+ if self .start_after :
191
+ path += f"&startAfter={ Utils .quote_key (self .start_after )} "
192
+ if self .start :
193
+ path += f"&start={ self .start } "
194
+ if self .page_size :
195
+ path += f"&pageSize={ self .page_size } "
196
+ if self .metadata_only :
197
+ path += "&metadataOnly=true"
198
+
199
+ self .url = "{0}/databases/{1}/{2}" .format (server_node .url , server_node .database , path )
200
+
201
+ def set_response (self , response ):
202
+ if response is None :
203
+ return
204
+
205
+ response = response .json ()
206
+ if "Error" in response :
207
+ raise exceptions .ErrorResponseException (response ["Error" ])
208
+ return response
209
+
210
+
114
211
class DeleteDocumentCommand (RavenCommand ):
115
212
def __init__ (self , key , change_vector = None ):
116
213
super (DeleteDocumentCommand , self ).__init__ (method = "DELETE" )
0 commit comments