add Clone methods for query builders (#10)

Summary:
Pull Request resolved: https://github.com/facebookincubator/ent/pull/10

Closes T46957221

Reviewed By: idoshveki

Differential Revision: D16278371

fbshipit-source-id: ca2b038fccb8fca6a7e8261444de27bdd63d0b00
This commit is contained in:
Ariel Mashraki
2019-07-16 03:29:17 -07:00
committed by Facebook Github Bot
parent b5cdb810b8
commit dbe2afb946
19 changed files with 346 additions and 48 deletions

View File

@@ -249,6 +249,22 @@ func (bq *BoringQuery) ExistX(ctx context.Context) bool {
return exist
}
// Clone returns a duplicate of the query builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (bq *BoringQuery) Clone() *BoringQuery {
return &BoringQuery{
config: bq.config,
limit: bq.limit,
offset: bq.offset,
order: append([]Order{}, bq.order...),
unique: append([]string{}, bq.unique...),
predicates: append([]ent.Predicate{}, bq.predicates...),
// clone intermediate queries.
sql: bq.sql.Clone(),
gremlin: bq.gremlin.Clone(),
}
}
// GroupBy used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
func (bq *BoringQuery) GroupBy(field string, fields ...string) *BoringGroupBy {