test seven
This commit is contained in:
182
ent/client.go
182
ent/client.go
@ -13,6 +13,7 @@ import (
|
||||
"api/ent/card"
|
||||
"api/ent/group"
|
||||
"api/ent/ma"
|
||||
"api/ent/sev"
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
|
||||
@ -33,6 +34,8 @@ type Client struct {
|
||||
Group *GroupClient
|
||||
// Ma is the client for interacting with the Ma builders.
|
||||
Ma *MaClient
|
||||
// Sev is the client for interacting with the Sev builders.
|
||||
Sev *SevClient
|
||||
// Ue is the client for interacting with the Ue builders.
|
||||
Ue *UeClient
|
||||
// User is the client for interacting with the User builders.
|
||||
@ -53,6 +56,7 @@ func (c *Client) init() {
|
||||
c.Card = NewCardClient(c.config)
|
||||
c.Group = NewGroupClient(c.config)
|
||||
c.Ma = NewMaClient(c.config)
|
||||
c.Sev = NewSevClient(c.config)
|
||||
c.Ue = NewUeClient(c.config)
|
||||
c.User = NewUserClient(c.config)
|
||||
}
|
||||
@ -140,6 +144,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
Card: NewCardClient(cfg),
|
||||
Group: NewGroupClient(cfg),
|
||||
Ma: NewMaClient(cfg),
|
||||
Sev: NewSevClient(cfg),
|
||||
Ue: NewUeClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
}, nil
|
||||
@ -164,6 +169,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
Card: NewCardClient(cfg),
|
||||
Group: NewGroupClient(cfg),
|
||||
Ma: NewMaClient(cfg),
|
||||
Sev: NewSevClient(cfg),
|
||||
Ue: NewUeClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
}, nil
|
||||
@ -194,21 +200,21 @@ func (c *Client) Close() error {
|
||||
// Use adds the mutation hooks to all the entity clients.
|
||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
c.Card.Use(hooks...)
|
||||
c.Group.Use(hooks...)
|
||||
c.Ma.Use(hooks...)
|
||||
c.Ue.Use(hooks...)
|
||||
c.User.Use(hooks...)
|
||||
for _, n := range []interface{ Use(...Hook) }{
|
||||
c.Card, c.Group, c.Ma, c.Sev, c.Ue, c.User,
|
||||
} {
|
||||
n.Use(hooks...)
|
||||
}
|
||||
}
|
||||
|
||||
// Intercept adds the query interceptors to all the entity clients.
|
||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
c.Card.Intercept(interceptors...)
|
||||
c.Group.Intercept(interceptors...)
|
||||
c.Ma.Intercept(interceptors...)
|
||||
c.Ue.Intercept(interceptors...)
|
||||
c.User.Intercept(interceptors...)
|
||||
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||
c.Card, c.Group, c.Ma, c.Sev, c.Ue, c.User,
|
||||
} {
|
||||
n.Intercept(interceptors...)
|
||||
}
|
||||
}
|
||||
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
@ -220,6 +226,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
return c.Group.mutate(ctx, m)
|
||||
case *MaMutation:
|
||||
return c.Ma.mutate(ctx, m)
|
||||
case *SevMutation:
|
||||
return c.Sev.mutate(ctx, m)
|
||||
case *UeMutation:
|
||||
return c.Ue.mutate(ctx, m)
|
||||
case *UserMutation:
|
||||
@ -631,6 +639,140 @@ func (c *MaClient) mutate(ctx context.Context, m *MaMutation) (Value, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// SevClient is a client for the Sev schema.
|
||||
type SevClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewSevClient returns a client for the Sev from the given config.
|
||||
func NewSevClient(c config) *SevClient {
|
||||
return &SevClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `sev.Hooks(f(g(h())))`.
|
||||
func (c *SevClient) Use(hooks ...Hook) {
|
||||
c.hooks.Sev = append(c.hooks.Sev, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `sev.Intercept(f(g(h())))`.
|
||||
func (c *SevClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Sev = append(c.inters.Sev, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Sev entity.
|
||||
func (c *SevClient) Create() *SevCreate {
|
||||
mutation := newSevMutation(c.config, OpCreate)
|
||||
return &SevCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Sev entities.
|
||||
func (c *SevClient) CreateBulk(builders ...*SevCreate) *SevCreateBulk {
|
||||
return &SevCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Sev.
|
||||
func (c *SevClient) Update() *SevUpdate {
|
||||
mutation := newSevMutation(c.config, OpUpdate)
|
||||
return &SevUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *SevClient) UpdateOne(s *Sev) *SevUpdateOne {
|
||||
mutation := newSevMutation(c.config, OpUpdateOne, withSev(s))
|
||||
return &SevUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *SevClient) UpdateOneID(id int) *SevUpdateOne {
|
||||
mutation := newSevMutation(c.config, OpUpdateOne, withSevID(id))
|
||||
return &SevUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Sev.
|
||||
func (c *SevClient) Delete() *SevDelete {
|
||||
mutation := newSevMutation(c.config, OpDelete)
|
||||
return &SevDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *SevClient) DeleteOne(s *Sev) *SevDeleteOne {
|
||||
return c.DeleteOneID(s.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *SevClient) DeleteOneID(id int) *SevDeleteOne {
|
||||
builder := c.Delete().Where(sev.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &SevDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Sev.
|
||||
func (c *SevClient) Query() *SevQuery {
|
||||
return &SevQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeSev},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Sev entity by its id.
|
||||
func (c *SevClient) Get(ctx context.Context, id int) (*Sev, error) {
|
||||
return c.Query().Where(sev.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *SevClient) GetX(ctx context.Context, id int) *Sev {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryOwner queries the owner edge of a Sev.
|
||||
func (c *SevClient) QueryOwner(s *Sev) *UserQuery {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := s.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sev.Table, sev.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, sev.OwnerTable, sev.OwnerColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SevClient) Hooks() []Hook {
|
||||
return c.hooks.Sev
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *SevClient) Interceptors() []Interceptor {
|
||||
return c.inters.Sev
|
||||
}
|
||||
|
||||
func (c *SevClient) mutate(ctx context.Context, m *SevMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&SevCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&SevUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&SevUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&SevDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Sev mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// UeClient is a client for the Ue schema.
|
||||
type UeClient struct {
|
||||
config
|
||||
@ -906,6 +1048,22 @@ func (c *UserClient) QueryMa(u *User) *MaQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySev queries the sev edge of a User.
|
||||
func (c *UserClient) QuerySev(u *User) *SevQuery {
|
||||
query := (&SevClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(sev.Table, sev.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.SevTable, user.SevColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *UserClient) Hooks() []Hook {
|
||||
return c.hooks.User
|
||||
@ -934,9 +1092,9 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error)
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
Card, Group, Ma, Ue, User []ent.Hook
|
||||
Card, Group, Ma, Sev, Ue, User []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
Card, Group, Ma, Ue, User []ent.Interceptor
|
||||
Card, Group, Ma, Sev, Ue, User []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
Reference in New Issue
Block a user