MCPcopy
hub / github.com/ent/ent / QueryEdges

Function QueryEdges

dialect/sql/sqlgraph/graph.go:960–990  ·  view source on GitHub ↗

QueryEdges queries the edges in the graph and scans the result with the given dest function.

(ctx context.Context, drv dialect.Driver, spec *EdgeQuerySpec)

Source from the content-addressed store, hash-verified

958
959// QueryEdges queries the edges in the graph and scans the result with the given dest function.
960func QueryEdges(ctx context.Context, drv dialect.Driver, spec *EdgeQuerySpec) error {
961 if len(spec.Edge.Columns) != 2 {
962 return fmt.Errorf("sqlgraph: edge query requires 2 columns (out, in)")
963 }
964 out, in := spec.Edge.Columns[0], spec.Edge.Columns[1]
965 if spec.Edge.Inverse {
966 out, in = in, out
967 }
968 selector := sql.Dialect(drv.Dialect()).
969 Select(out, in).
970 From(sql.Table(spec.Edge.Table).Schema(spec.Edge.Schema))
971 if p := spec.Predicate; p != nil {
972 p(selector)
973 }
974 rows := &sql.Rows{}
975 query, args := selector.Query()
976 if err := drv.Query(ctx, query, args, rows); err != nil {
977 return err
978 }
979 defer rows.Close()
980 for rows.Next() {
981 values := spec.ScanValues()
982 if err := rows.Scan(values[0], values[1]); err != nil {
983 return err
984 }
985 if err := spec.Assign(values[0], values[1]); err != nil {
986 return err
987 }
988 }
989 return rows.Err()
990}
991
992type query struct {
993 graph

Callers 2

TestQueryEdgesFunction · 0.85
TestQueryEdgesSchemaFunction · 0.85

Calls 11

DialectFunction · 0.92
TableFunction · 0.92
DialectMethod · 0.65
QueryMethod · 0.65
CloseMethod · 0.65
NextMethod · 0.65
ScanMethod · 0.65
ErrMethod · 0.65
FromMethod · 0.45
SelectMethod · 0.45
SchemaMethod · 0.45

Tested by 2

TestQueryEdgesFunction · 0.68
TestQueryEdgesSchemaFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…