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

Method Contains

graph/sql/iterator.go:350–397  ·  view source on GitHub ↗
(ctx context.Context, v graph.Ref)

Source from the content-addressed store, hash-verified

348}
349
350func (it *iteratorContains) Contains(ctx context.Context, v graph.Ref) bool {
351 it.ensureColumns()
352 sel := it.query
353 sel.Where = append([]Where{}, sel.Where...)
354 switch v := v.(type) {
355 case NodeHash:
356 i, ok := it.cind[quad.Any]
357 if !ok {
358 return false
359 }
360 f := it.query.Fields[i]
361 sel.WhereEq(f.Table, f.Name, v)
362 case QuadHashes:
363 for _, d := range quad.Directions {
364 i, ok := it.cind[d]
365 if !ok {
366 return false
367 }
368 h := v.Get(d)
369 if !h.Valid() {
370 continue
371 }
372 f := it.query.Fields[i]
373 sel.WhereEq(f.Table, f.Name, NodeHash{h})
374 }
375 default:
376 return false
377 }
378
379 rows, err := it.qs.Query(ctx, sel)
380 if err != nil {
381 it.err = err
382 return false
383 }
384 if it.query.nextPath {
385 if it.nextPathRows != nil {
386 _ = it.nextPathRows.Close()
387 }
388 it.nextPathRows = rows
389 } else {
390 defer rows.Close()
391 }
392 if !rows.Next() {
393 it.err = rows.Err()
394 return false
395 }
396 return it.scanValue(rows)
397}
398
399func (it *iteratorContains) NextPath(ctx context.Context) bool {
400 if it.err != nil {

Callers

nothing calls this directly

Calls 9

ensureColumnsMethod · 0.80
WhereEqMethod · 0.80
ValidMethod · 0.80
QueryMethod · 0.80
scanValueMethod · 0.80
CloseMethod · 0.65
NextMethod · 0.65
ErrMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected