mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
entc/gen: allow users to alter Query initialization using templates (#1453)
* Templating: Allow user to alter Query struct init * Update entc/gen/template/dialect/sql/query.tmpl Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * pr feedback * renamed template * changed sql to * * to tabs * removed old template * update bin-data * Update entc/integration/template/ent/template/query.tmpl Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * restore newline * update bindata Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
@@ -208,7 +208,10 @@ func (c *GroupClient) DeleteOneID(id int) *GroupDeleteOne {
|
||||
|
||||
// Query returns a query builder for Group.
|
||||
func (c *GroupClient) Query() *GroupQuery {
|
||||
return &GroupQuery{config: c.config}
|
||||
return &GroupQuery{
|
||||
config: c.config,
|
||||
extra: "Group",
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Group entity by its id.
|
||||
@@ -296,7 +299,10 @@ func (c *PetClient) DeleteOneID(id int) *PetDeleteOne {
|
||||
|
||||
// Query returns a query builder for Pet.
|
||||
func (c *PetClient) Query() *PetQuery {
|
||||
return &PetQuery{config: c.config}
|
||||
return &PetQuery{
|
||||
config: c.config,
|
||||
extra: "Pet",
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Pet entity by its id.
|
||||
@@ -400,7 +406,10 @@ func (c *UserClient) DeleteOneID(id int) *UserDeleteOne {
|
||||
|
||||
// Query returns a query builder for User.
|
||||
func (c *UserClient) Query() *UserQuery {
|
||||
return &UserQuery{config: c.config}
|
||||
return &UserQuery{
|
||||
config: c.config,
|
||||
extra: "User",
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a User entity by its id.
|
||||
|
||||
@@ -28,6 +28,10 @@ type GroupQuery struct {
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
predicates []predicate.Group
|
||||
|
||||
// additional query fields.
|
||||
extra string
|
||||
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
|
||||
@@ -32,6 +32,10 @@ type PetQuery struct {
|
||||
// eager-loading edges.
|
||||
withOwner *UserQuery
|
||||
withFKs bool
|
||||
|
||||
// additional query fields.
|
||||
extra string
|
||||
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
|
||||
17
entc/integration/template/ent/template/query.tmpl
Normal file
17
entc/integration/template/ent/template/query.tmpl
Normal file
@@ -0,0 +1,17 @@
|
||||
{{/*
|
||||
Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
This source code is licensed under the Apache 2.0 license found
|
||||
in the LICENSE file in the root directory of this source tree.
|
||||
*/}}
|
||||
|
||||
{{/* The line below tells Intellij/GoLand to enable the autocompletion based *gen.Graph type. */}}
|
||||
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}
|
||||
|
||||
{{ define "dialect/sql/query/fields/additional/extra" }}
|
||||
// additional query fields.
|
||||
extra string
|
||||
{{ end }}
|
||||
|
||||
{{ define "dialect/sql/query/fields/init/extra" }}
|
||||
extra: "{{ $.Name }}",
|
||||
{{ end }}
|
||||
@@ -33,6 +33,10 @@ type UserQuery struct {
|
||||
// eager-loading edges.
|
||||
withPets *PetQuery
|
||||
withFriends *UserQuery
|
||||
|
||||
// additional query fields.
|
||||
extra string
|
||||
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
|
||||
Reference in New Issue
Block a user