forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_stream_command.go
54 lines (42 loc) · 1.25 KB
/
query_stream_command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package ravendb
import (
"net/http"
)
var (
_ RavenCommand = &QueryStreamCommand{}
)
type QueryStreamCommand struct {
RavenCommandBase
_conventions *DocumentConventions
_indexQuery *IndexQuery
Result *StreamResultResponse
}
func NewQueryStreamCommand(conventions *DocumentConventions, indexQuery *IndexQuery) *QueryStreamCommand {
panicIf(indexQuery == nil, "IndexQuery cannot be null")
// TODO: validate convention
cmd := &QueryStreamCommand{
RavenCommandBase: NewRavenCommandBase(),
_conventions: conventions,
_indexQuery: indexQuery,
}
cmd.IsReadRequest = true
return cmd
}
func (c *QueryStreamCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
url := node.URL + "/databases/" + node.Database + "/streams/queries"
m := jsonExtensionsWriteIndexQuery(c._conventions, c._indexQuery)
d, err := jsonMarshal(m)
if err != nil {
return nil, err
}
return NewHttpPost(url, d)
}
func (c *QueryStreamCommand) processResponse(cache *httpCache, response *http.Response, url string) (responseDisposeHandling, error) {
// TODO: return an error if response.Body is nil
streamResponse := &StreamResultResponse{
Response: response,
Stream: response.Body,
}
c.Result = streamResponse
return responseDisposeHandlingManually, nil
}