MCPcopy
hub / github.com/cayleygraph/cayley / ServeV1WriteNQuad

Method ServeV1WriteNQuad

internal/http/write.go:100–140  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, params httprouter.Params)

Source from the content-addressed store, hash-verified

98}
99
100func (api *API) ServeV1WriteNQuad(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
101 if api.config.ReadOnly {
102 jsonResponse(w, 400, "Database is read-only.")
103 return
104 }
105
106 formFile, _, err := r.FormFile("NQuadFile")
107 if err != nil {
108 clog.Errorf("%v", err)
109 jsonResponse(w, 500, "Couldn't read file: "+err.Error())
110 return
111 }
112 defer formFile.Close()
113
114 blockSize, blockErr := strconv.Atoi(r.URL.Query().Get("block_size"))
115 if blockErr != nil {
116 blockSize = quad.DefaultBatch
117 }
118
119 quadReader, err := decompressor.New(formFile)
120 // TODO(kortschak) Make this configurable from the web UI.
121 dec := nquads.NewReader(quadReader, false)
122
123 h, err := api.GetHandleForRequest(r)
124 if err != nil {
125 jsonResponse(w, 400, err)
126 return
127 }
128 qw := graph.NewWriter(h.QuadWriter)
129 n, err := quad.CopyBatch(qw, dec, blockSize)
130 if err != nil {
131 jsonResponse(w, 400, err)
132 return
133 }
134 err = qw.Close()
135 if err != nil {
136 jsonResponse(w, 400, err)
137 return
138 }
139 fmt.Fprintf(w, "{\"result\": \"Successfully wrote %d quads.\"}", n)
140}
141
142func (api *API) ServeV1Delete(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
143 if api.config.ReadOnly {

Callers

nothing calls this directly

Calls 9

GetHandleForRequestMethod · 0.95
ErrorfFunction · 0.92
NewFunction · 0.92
NewWriterFunction · 0.92
QueryMethod · 0.80
jsonResponseFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected