QueryEdges queries the edges in the graph and scans the result with the given dest function.
(ctx context.Context, drv dialect.Driver, spec *EdgeQuerySpec)
| 958 | |
| 959 | // QueryEdges queries the edges in the graph and scans the result with the given dest function. |
| 960 | func 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 | |
| 992 | type query struct { |
| 993 | graph |