entc/gen: reduce the usage of DISTINCT in queries (#3305)

Most queries are not graph traversals but rather regular table scans,
in which case the DISTINCT clause is not needed as duplicates cannot be
returned (unless query was modified by the user).
This commit is contained in:
Ariel Mashraki
2023-02-06 22:40:50 +02:00
committed by GitHub
parent 138bd2bc1d
commit 939c7cff1a
125 changed files with 508 additions and 1474 deletions

View File

@@ -577,6 +577,17 @@ type QuerySpec struct {
Assign func(columns []string, values []any) error
}
// NewQuerySpec creates a new node query spec.
func NewQuerySpec(table string, columns []string, id *FieldSpec) *QuerySpec {
return &QuerySpec{
Node: &NodeSpec{
ID: id,
Table: table,
Columns: columns,
},
}
}
// QueryNodes queries the nodes in the graph query and scans them to the given values.
func QueryNodes(ctx context.Context, drv dialect.Driver, spec *QuerySpec) error {
builder := sql.Dialect(drv.Dialect())