Model schema update
Ent generate
This commit is contained in:
parent
69fe4c6cef
commit
b3e85a3e5c
325
ent/client.go
325
ent/client.go
@ -11,11 +11,14 @@ import (
|
||||
|
||||
"portfolio-backend/ent/migrate"
|
||||
|
||||
"portfolio-backend/ent/project"
|
||||
"portfolio-backend/ent/team"
|
||||
"portfolio-backend/ent/user"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// Client is the client that holds all ent builders.
|
||||
@ -23,6 +26,10 @@ type Client struct {
|
||||
config
|
||||
// Schema is the client for creating, migrating and dropping schema.
|
||||
Schema *migrate.Schema
|
||||
// Project is the client for interacting with the Project builders.
|
||||
Project *ProjectClient
|
||||
// Team is the client for interacting with the Team builders.
|
||||
Team *TeamClient
|
||||
// User is the client for interacting with the User builders.
|
||||
User *UserClient
|
||||
}
|
||||
@ -36,6 +43,8 @@ func NewClient(opts ...Option) *Client {
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.Project = NewProjectClient(c.config)
|
||||
c.Team = NewTeamClient(c.config)
|
||||
c.User = NewUserClient(c.config)
|
||||
}
|
||||
|
||||
@ -129,6 +138,8 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Project: NewProjectClient(cfg),
|
||||
Team: NewTeamClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
@ -149,6 +160,8 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Project: NewProjectClient(cfg),
|
||||
Team: NewTeamClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
@ -156,7 +169,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// User.
|
||||
// Project.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
func (c *Client) Debug() *Client {
|
||||
@ -178,18 +191,26 @@ 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.Project.Use(hooks...)
|
||||
c.Team.Use(hooks...)
|
||||
c.User.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.Project.Intercept(interceptors...)
|
||||
c.Team.Intercept(interceptors...)
|
||||
c.User.Intercept(interceptors...)
|
||||
}
|
||||
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *ProjectMutation:
|
||||
return c.Project.mutate(ctx, m)
|
||||
case *TeamMutation:
|
||||
return c.Team.mutate(ctx, m)
|
||||
case *UserMutation:
|
||||
return c.User.mutate(ctx, m)
|
||||
default:
|
||||
@ -197,6 +218,304 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectClient is a client for the Project schema.
|
||||
type ProjectClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewProjectClient returns a client for the Project from the given config.
|
||||
func NewProjectClient(c config) *ProjectClient {
|
||||
return &ProjectClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `project.Hooks(f(g(h())))`.
|
||||
func (c *ProjectClient) Use(hooks ...Hook) {
|
||||
c.hooks.Project = append(c.hooks.Project, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `project.Intercept(f(g(h())))`.
|
||||
func (c *ProjectClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Project = append(c.inters.Project, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Project entity.
|
||||
func (c *ProjectClient) Create() *ProjectCreate {
|
||||
mutation := newProjectMutation(c.config, OpCreate)
|
||||
return &ProjectCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Project entities.
|
||||
func (c *ProjectClient) CreateBulk(builders ...*ProjectCreate) *ProjectCreateBulk {
|
||||
return &ProjectCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *ProjectClient) MapCreateBulk(slice any, setFunc func(*ProjectCreate, int)) *ProjectCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &ProjectCreateBulk{err: fmt.Errorf("calling to ProjectClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*ProjectCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &ProjectCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Project.
|
||||
func (c *ProjectClient) Update() *ProjectUpdate {
|
||||
mutation := newProjectMutation(c.config, OpUpdate)
|
||||
return &ProjectUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *ProjectClient) UpdateOne(pr *Project) *ProjectUpdateOne {
|
||||
mutation := newProjectMutation(c.config, OpUpdateOne, withProject(pr))
|
||||
return &ProjectUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *ProjectClient) UpdateOneID(id int) *ProjectUpdateOne {
|
||||
mutation := newProjectMutation(c.config, OpUpdateOne, withProjectID(id))
|
||||
return &ProjectUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Project.
|
||||
func (c *ProjectClient) Delete() *ProjectDelete {
|
||||
mutation := newProjectMutation(c.config, OpDelete)
|
||||
return &ProjectDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *ProjectClient) DeleteOne(pr *Project) *ProjectDeleteOne {
|
||||
return c.DeleteOneID(pr.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *ProjectClient) DeleteOneID(id int) *ProjectDeleteOne {
|
||||
builder := c.Delete().Where(project.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &ProjectDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Project.
|
||||
func (c *ProjectClient) Query() *ProjectQuery {
|
||||
return &ProjectQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeProject},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Project entity by its id.
|
||||
func (c *ProjectClient) Get(ctx context.Context, id int) (*Project, error) {
|
||||
return c.Query().Where(project.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *ProjectClient) GetX(ctx context.Context, id int) *Project {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryTeam queries the team edge of a Project.
|
||||
func (c *ProjectClient) QueryTeam(pr *Project) *TeamQuery {
|
||||
query := (&TeamClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := pr.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(project.Table, project.FieldID, id),
|
||||
sqlgraph.To(team.Table, team.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, project.TeamTable, project.TeamColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(pr.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *ProjectClient) Hooks() []Hook {
|
||||
return c.hooks.Project
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *ProjectClient) Interceptors() []Interceptor {
|
||||
return c.inters.Project
|
||||
}
|
||||
|
||||
func (c *ProjectClient) mutate(ctx context.Context, m *ProjectMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&ProjectCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&ProjectUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&ProjectUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&ProjectDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Project mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// TeamClient is a client for the Team schema.
|
||||
type TeamClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewTeamClient returns a client for the Team from the given config.
|
||||
func NewTeamClient(c config) *TeamClient {
|
||||
return &TeamClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `team.Hooks(f(g(h())))`.
|
||||
func (c *TeamClient) Use(hooks ...Hook) {
|
||||
c.hooks.Team = append(c.hooks.Team, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `team.Intercept(f(g(h())))`.
|
||||
func (c *TeamClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Team = append(c.inters.Team, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Team entity.
|
||||
func (c *TeamClient) Create() *TeamCreate {
|
||||
mutation := newTeamMutation(c.config, OpCreate)
|
||||
return &TeamCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Team entities.
|
||||
func (c *TeamClient) CreateBulk(builders ...*TeamCreate) *TeamCreateBulk {
|
||||
return &TeamCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *TeamClient) MapCreateBulk(slice any, setFunc func(*TeamCreate, int)) *TeamCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &TeamCreateBulk{err: fmt.Errorf("calling to TeamClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*TeamCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &TeamCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Team.
|
||||
func (c *TeamClient) Update() *TeamUpdate {
|
||||
mutation := newTeamMutation(c.config, OpUpdate)
|
||||
return &TeamUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *TeamClient) UpdateOne(t *Team) *TeamUpdateOne {
|
||||
mutation := newTeamMutation(c.config, OpUpdateOne, withTeam(t))
|
||||
return &TeamUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *TeamClient) UpdateOneID(id int) *TeamUpdateOne {
|
||||
mutation := newTeamMutation(c.config, OpUpdateOne, withTeamID(id))
|
||||
return &TeamUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Team.
|
||||
func (c *TeamClient) Delete() *TeamDelete {
|
||||
mutation := newTeamMutation(c.config, OpDelete)
|
||||
return &TeamDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *TeamClient) DeleteOne(t *Team) *TeamDeleteOne {
|
||||
return c.DeleteOneID(t.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *TeamClient) DeleteOneID(id int) *TeamDeleteOne {
|
||||
builder := c.Delete().Where(team.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &TeamDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Team.
|
||||
func (c *TeamClient) Query() *TeamQuery {
|
||||
return &TeamQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeTeam},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Team entity by its id.
|
||||
func (c *TeamClient) Get(ctx context.Context, id int) (*Team, error) {
|
||||
return c.Query().Where(team.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *TeamClient) GetX(ctx context.Context, id int) *Team {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryProjects queries the projects edge of a Team.
|
||||
func (c *TeamClient) QueryProjects(t *Team) *ProjectQuery {
|
||||
query := (&ProjectClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := t.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(team.Table, team.FieldID, id),
|
||||
sqlgraph.To(project.Table, project.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, team.ProjectsTable, team.ProjectsColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(t.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *TeamClient) Hooks() []Hook {
|
||||
return c.hooks.Team
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *TeamClient) Interceptors() []Interceptor {
|
||||
return c.inters.Team
|
||||
}
|
||||
|
||||
func (c *TeamClient) mutate(ctx context.Context, m *TeamMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&TeamCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&TeamUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&TeamUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&TeamDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Team mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// UserClient is a client for the User schema.
|
||||
type UserClient struct {
|
||||
config
|
||||
@ -333,9 +652,9 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error)
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
User []ent.Hook
|
||||
Project, Team, User []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
User []ent.Interceptor
|
||||
Project, Team, User []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
||||
@ -6,6 +6,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"portfolio-backend/ent/project"
|
||||
"portfolio-backend/ent/team"
|
||||
"portfolio-backend/ent/user"
|
||||
"reflect"
|
||||
"sync"
|
||||
@ -73,6 +75,8 @@ var (
|
||||
func checkColumn(table, column string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
project.Table: project.ValidColumn,
|
||||
team.Table: team.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
})
|
||||
})
|
||||
|
||||
@ -8,6 +8,30 @@ import (
|
||||
"portfolio-backend/ent"
|
||||
)
|
||||
|
||||
// The ProjectFunc type is an adapter to allow the use of ordinary
|
||||
// function as Project mutator.
|
||||
type ProjectFunc func(context.Context, *ent.ProjectMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f ProjectFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.ProjectMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ProjectMutation", m)
|
||||
}
|
||||
|
||||
// The TeamFunc type is an adapter to allow the use of ordinary
|
||||
// function as Team mutator.
|
||||
type TeamFunc func(context.Context, *ent.TeamMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f TeamFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.TeamMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TeamMutation", m)
|
||||
}
|
||||
|
||||
// The UserFunc type is an adapter to allow the use of ordinary
|
||||
// function as User mutator.
|
||||
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
|
||||
|
||||
@ -8,6 +8,37 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// ProjectsColumns holds the columns for the "projects" table.
|
||||
ProjectsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString, Unique: true},
|
||||
{Name: "team_projects", Type: field.TypeInt, Nullable: true},
|
||||
}
|
||||
// ProjectsTable holds the schema information for the "projects" table.
|
||||
ProjectsTable = &schema.Table{
|
||||
Name: "projects",
|
||||
Columns: ProjectsColumns,
|
||||
PrimaryKey: []*schema.Column{ProjectsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "projects_teams_projects",
|
||||
Columns: []*schema.Column{ProjectsColumns[2]},
|
||||
RefColumns: []*schema.Column{TeamsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// TeamsColumns holds the columns for the "teams" table.
|
||||
TeamsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
}
|
||||
// TeamsTable holds the schema information for the "teams" table.
|
||||
TeamsTable = &schema.Table{
|
||||
Name: "teams",
|
||||
Columns: TeamsColumns,
|
||||
PrimaryKey: []*schema.Column{TeamsColumns[0]},
|
||||
}
|
||||
// UsersColumns holds the columns for the "users" table.
|
||||
UsersColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
@ -22,9 +53,12 @@ var (
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
ProjectsTable,
|
||||
TeamsTable,
|
||||
UsersTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
ProjectsTable.ForeignKeys[0].RefTable = TeamsTable
|
||||
}
|
||||
|
||||
816
ent/mutation.go
816
ent/mutation.go
@ -7,6 +7,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"portfolio-backend/ent/predicate"
|
||||
"portfolio-backend/ent/project"
|
||||
"portfolio-backend/ent/team"
|
||||
"portfolio-backend/ent/user"
|
||||
"sync"
|
||||
|
||||
@ -23,9 +25,823 @@ const (
|
||||
OpUpdateOne = ent.OpUpdateOne
|
||||
|
||||
// Node types.
|
||||
TypeProject = "Project"
|
||||
TypeTeam = "Team"
|
||||
TypeUser = "User"
|
||||
)
|
||||
|
||||
// ProjectMutation represents an operation that mutates the Project nodes in the graph.
|
||||
type ProjectMutation struct {
|
||||
config
|
||||
op Op
|
||||
typ string
|
||||
id *int
|
||||
name *string
|
||||
clearedFields map[string]struct{}
|
||||
team *int
|
||||
clearedteam bool
|
||||
done bool
|
||||
oldValue func(context.Context) (*Project, error)
|
||||
predicates []predicate.Project
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*ProjectMutation)(nil)
|
||||
|
||||
// projectOption allows management of the mutation configuration using functional options.
|
||||
type projectOption func(*ProjectMutation)
|
||||
|
||||
// newProjectMutation creates new mutation for the Project entity.
|
||||
func newProjectMutation(c config, op Op, opts ...projectOption) *ProjectMutation {
|
||||
m := &ProjectMutation{
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeProject,
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// withProjectID sets the ID field of the mutation.
|
||||
func withProjectID(id int) projectOption {
|
||||
return func(m *ProjectMutation) {
|
||||
var (
|
||||
err error
|
||||
once sync.Once
|
||||
value *Project
|
||||
)
|
||||
m.oldValue = func(ctx context.Context) (*Project, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().Project.Get(ctx, id)
|
||||
}
|
||||
})
|
||||
return value, err
|
||||
}
|
||||
m.id = &id
|
||||
}
|
||||
}
|
||||
|
||||
// withProject sets the old Project of the mutation.
|
||||
func withProject(node *Project) projectOption {
|
||||
return func(m *ProjectMutation) {
|
||||
m.oldValue = func(context.Context) (*Project, error) {
|
||||
return node, nil
|
||||
}
|
||||
m.id = &node.ID
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||
func (m ProjectMutation) Client() *Client {
|
||||
client := &Client{config: m.config}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||
// it returns an error otherwise.
|
||||
func (m ProjectMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *ProjectMutation) ID() (id int, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
return *m.id, true
|
||||
}
|
||||
|
||||
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *ProjectMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []int{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
return m.Client().Project.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (m *ProjectMutation) SetName(s string) {
|
||||
m.name = &s
|
||||
}
|
||||
|
||||
// Name returns the value of the "name" field in the mutation.
|
||||
func (m *ProjectMutation) Name() (r string, exists bool) {
|
||||
v := m.name
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldName returns the old "name" field's value of the Project entity.
|
||||
// If the Project object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ProjectMutation) OldName(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldName is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldName requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldName: %w", err)
|
||||
}
|
||||
return oldValue.Name, nil
|
||||
}
|
||||
|
||||
// ResetName resets all changes to the "name" field.
|
||||
func (m *ProjectMutation) ResetName() {
|
||||
m.name = nil
|
||||
}
|
||||
|
||||
// SetTeamID sets the "team" edge to the Team entity by id.
|
||||
func (m *ProjectMutation) SetTeamID(id int) {
|
||||
m.team = &id
|
||||
}
|
||||
|
||||
// ClearTeam clears the "team" edge to the Team entity.
|
||||
func (m *ProjectMutation) ClearTeam() {
|
||||
m.clearedteam = true
|
||||
}
|
||||
|
||||
// TeamCleared reports if the "team" edge to the Team entity was cleared.
|
||||
func (m *ProjectMutation) TeamCleared() bool {
|
||||
return m.clearedteam
|
||||
}
|
||||
|
||||
// TeamID returns the "team" edge ID in the mutation.
|
||||
func (m *ProjectMutation) TeamID() (id int, exists bool) {
|
||||
if m.team != nil {
|
||||
return *m.team, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// TeamIDs returns the "team" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// TeamID instead. It exists only for internal usage by the builders.
|
||||
func (m *ProjectMutation) TeamIDs() (ids []int) {
|
||||
if id := m.team; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetTeam resets all changes to the "team" edge.
|
||||
func (m *ProjectMutation) ResetTeam() {
|
||||
m.team = nil
|
||||
m.clearedteam = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ProjectMutation builder.
|
||||
func (m *ProjectMutation) Where(ps ...predicate.Project) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the ProjectMutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *ProjectMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.Project, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *ProjectMutation) Op() Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *ProjectMutation) SetOp(op Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (Project).
|
||||
func (m *ProjectMutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *ProjectMutation) Fields() []string {
|
||||
fields := make([]string, 0, 1)
|
||||
if m.name != nil {
|
||||
fields = append(fields, project.FieldName)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *ProjectMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case project.FieldName:
|
||||
return m.Name()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *ProjectMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case project.FieldName:
|
||||
return m.OldName(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown Project field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *ProjectMutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case project.FieldName:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetName(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Project field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *ProjectMutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *ProjectMutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *ProjectMutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown Project numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *ProjectMutation) ClearedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *ProjectMutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *ProjectMutation) ClearField(name string) error {
|
||||
return fmt.Errorf("unknown Project nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *ProjectMutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case project.FieldName:
|
||||
m.ResetName()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Project field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *ProjectMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
if m.team != nil {
|
||||
edges = append(edges, project.EdgeTeam)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *ProjectMutation) AddedIDs(name string) []ent.Value {
|
||||
switch name {
|
||||
case project.EdgeTeam:
|
||||
if id := m.team; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *ProjectMutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *ProjectMutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *ProjectMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
if m.clearedteam {
|
||||
edges = append(edges, project.EdgeTeam)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *ProjectMutation) EdgeCleared(name string) bool {
|
||||
switch name {
|
||||
case project.EdgeTeam:
|
||||
return m.clearedteam
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *ProjectMutation) ClearEdge(name string) error {
|
||||
switch name {
|
||||
case project.EdgeTeam:
|
||||
m.ClearTeam()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Project unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *ProjectMutation) ResetEdge(name string) error {
|
||||
switch name {
|
||||
case project.EdgeTeam:
|
||||
m.ResetTeam()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Project edge %s", name)
|
||||
}
|
||||
|
||||
// TeamMutation represents an operation that mutates the Team nodes in the graph.
|
||||
type TeamMutation struct {
|
||||
config
|
||||
op Op
|
||||
typ string
|
||||
id *int
|
||||
name *string
|
||||
clearedFields map[string]struct{}
|
||||
projects map[int]struct{}
|
||||
removedprojects map[int]struct{}
|
||||
clearedprojects bool
|
||||
done bool
|
||||
oldValue func(context.Context) (*Team, error)
|
||||
predicates []predicate.Team
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*TeamMutation)(nil)
|
||||
|
||||
// teamOption allows management of the mutation configuration using functional options.
|
||||
type teamOption func(*TeamMutation)
|
||||
|
||||
// newTeamMutation creates new mutation for the Team entity.
|
||||
func newTeamMutation(c config, op Op, opts ...teamOption) *TeamMutation {
|
||||
m := &TeamMutation{
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeTeam,
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// withTeamID sets the ID field of the mutation.
|
||||
func withTeamID(id int) teamOption {
|
||||
return func(m *TeamMutation) {
|
||||
var (
|
||||
err error
|
||||
once sync.Once
|
||||
value *Team
|
||||
)
|
||||
m.oldValue = func(ctx context.Context) (*Team, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().Team.Get(ctx, id)
|
||||
}
|
||||
})
|
||||
return value, err
|
||||
}
|
||||
m.id = &id
|
||||
}
|
||||
}
|
||||
|
||||
// withTeam sets the old Team of the mutation.
|
||||
func withTeam(node *Team) teamOption {
|
||||
return func(m *TeamMutation) {
|
||||
m.oldValue = func(context.Context) (*Team, error) {
|
||||
return node, nil
|
||||
}
|
||||
m.id = &node.ID
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||
func (m TeamMutation) Client() *Client {
|
||||
client := &Client{config: m.config}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||
// it returns an error otherwise.
|
||||
func (m TeamMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *TeamMutation) ID() (id int, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
return *m.id, true
|
||||
}
|
||||
|
||||
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *TeamMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []int{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
return m.Client().Team.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (m *TeamMutation) SetName(s string) {
|
||||
m.name = &s
|
||||
}
|
||||
|
||||
// Name returns the value of the "name" field in the mutation.
|
||||
func (m *TeamMutation) Name() (r string, exists bool) {
|
||||
v := m.name
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldName returns the old "name" field's value of the Team entity.
|
||||
// If the Team object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *TeamMutation) OldName(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldName is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldName requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldName: %w", err)
|
||||
}
|
||||
return oldValue.Name, nil
|
||||
}
|
||||
|
||||
// ResetName resets all changes to the "name" field.
|
||||
func (m *TeamMutation) ResetName() {
|
||||
m.name = nil
|
||||
}
|
||||
|
||||
// AddProjectIDs adds the "projects" edge to the Project entity by ids.
|
||||
func (m *TeamMutation) AddProjectIDs(ids ...int) {
|
||||
if m.projects == nil {
|
||||
m.projects = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
m.projects[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ClearProjects clears the "projects" edge to the Project entity.
|
||||
func (m *TeamMutation) ClearProjects() {
|
||||
m.clearedprojects = true
|
||||
}
|
||||
|
||||
// ProjectsCleared reports if the "projects" edge to the Project entity was cleared.
|
||||
func (m *TeamMutation) ProjectsCleared() bool {
|
||||
return m.clearedprojects
|
||||
}
|
||||
|
||||
// RemoveProjectIDs removes the "projects" edge to the Project entity by IDs.
|
||||
func (m *TeamMutation) RemoveProjectIDs(ids ...int) {
|
||||
if m.removedprojects == nil {
|
||||
m.removedprojects = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
delete(m.projects, ids[i])
|
||||
m.removedprojects[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// RemovedProjects returns the removed IDs of the "projects" edge to the Project entity.
|
||||
func (m *TeamMutation) RemovedProjectsIDs() (ids []int) {
|
||||
for id := range m.removedprojects {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ProjectsIDs returns the "projects" edge IDs in the mutation.
|
||||
func (m *TeamMutation) ProjectsIDs() (ids []int) {
|
||||
for id := range m.projects {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetProjects resets all changes to the "projects" edge.
|
||||
func (m *TeamMutation) ResetProjects() {
|
||||
m.projects = nil
|
||||
m.clearedprojects = false
|
||||
m.removedprojects = nil
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TeamMutation builder.
|
||||
func (m *TeamMutation) Where(ps ...predicate.Team) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the TeamMutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *TeamMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.Team, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *TeamMutation) Op() Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *TeamMutation) SetOp(op Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (Team).
|
||||
func (m *TeamMutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *TeamMutation) Fields() []string {
|
||||
fields := make([]string, 0, 1)
|
||||
if m.name != nil {
|
||||
fields = append(fields, team.FieldName)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *TeamMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case team.FieldName:
|
||||
return m.Name()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *TeamMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case team.FieldName:
|
||||
return m.OldName(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown Team field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *TeamMutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case team.FieldName:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetName(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Team field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *TeamMutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *TeamMutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *TeamMutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown Team numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *TeamMutation) ClearedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *TeamMutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *TeamMutation) ClearField(name string) error {
|
||||
return fmt.Errorf("unknown Team nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *TeamMutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case team.FieldName:
|
||||
m.ResetName()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Team field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *TeamMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
if m.projects != nil {
|
||||
edges = append(edges, team.EdgeProjects)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *TeamMutation) AddedIDs(name string) []ent.Value {
|
||||
switch name {
|
||||
case team.EdgeProjects:
|
||||
ids := make([]ent.Value, 0, len(m.projects))
|
||||
for id := range m.projects {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *TeamMutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
if m.removedprojects != nil {
|
||||
edges = append(edges, team.EdgeProjects)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *TeamMutation) RemovedIDs(name string) []ent.Value {
|
||||
switch name {
|
||||
case team.EdgeProjects:
|
||||
ids := make([]ent.Value, 0, len(m.removedprojects))
|
||||
for id := range m.removedprojects {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *TeamMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
if m.clearedprojects {
|
||||
edges = append(edges, team.EdgeProjects)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *TeamMutation) EdgeCleared(name string) bool {
|
||||
switch name {
|
||||
case team.EdgeProjects:
|
||||
return m.clearedprojects
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *TeamMutation) ClearEdge(name string) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown Team unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *TeamMutation) ResetEdge(name string) error {
|
||||
switch name {
|
||||
case team.EdgeProjects:
|
||||
m.ResetProjects()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Team edge %s", name)
|
||||
}
|
||||
|
||||
// UserMutation represents an operation that mutates the User nodes in the graph.
|
||||
type UserMutation struct {
|
||||
config
|
||||
|
||||
@ -6,5 +6,11 @@ import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Project is the predicate function for project builders.
|
||||
type Project func(*sql.Selector)
|
||||
|
||||
// Team is the predicate function for team builders.
|
||||
type Team func(*sql.Selector)
|
||||
|
||||
// User is the predicate function for user builders.
|
||||
type User func(*sql.Selector)
|
||||
|
||||
144
ent/project.go
Normal file
144
ent/project.go
Normal file
@ -0,0 +1,144 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"portfolio-backend/ent/project"
|
||||
"portfolio-backend/ent/team"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Project is the model entity for the Project schema.
|
||||
type Project struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the ProjectQuery when eager-loading is set.
|
||||
Edges ProjectEdges `json:"edges"`
|
||||
team_projects *int
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// ProjectEdges holds the relations/edges for other nodes in the graph.
|
||||
type ProjectEdges struct {
|
||||
// Team holds the value of the team edge.
|
||||
Team *Team `json:"team,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// TeamOrErr returns the Team value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e ProjectEdges) TeamOrErr() (*Team, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.Team == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: team.Label}
|
||||
}
|
||||
return e.Team, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "team"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Project) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case project.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case project.FieldName:
|
||||
values[i] = new(sql.NullString)
|
||||
case project.ForeignKeys[0]: // team_projects
|
||||
values[i] = new(sql.NullInt64)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Project fields.
|
||||
func (pr *Project) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case project.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
pr.ID = int(value.Int64)
|
||||
case project.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
pr.Name = value.String
|
||||
}
|
||||
case project.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field team_projects", value)
|
||||
} else if value.Valid {
|
||||
pr.team_projects = new(int)
|
||||
*pr.team_projects = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
pr.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Project.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (pr *Project) Value(name string) (ent.Value, error) {
|
||||
return pr.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryTeam queries the "team" edge of the Project entity.
|
||||
func (pr *Project) QueryTeam() *TeamQuery {
|
||||
return NewProjectClient(pr.config).QueryTeam(pr)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Project.
|
||||
// Note that you need to call Project.Unwrap() before calling this method if this Project
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (pr *Project) Update() *ProjectUpdateOne {
|
||||
return NewProjectClient(pr.config).UpdateOne(pr)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Project entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (pr *Project) Unwrap() *Project {
|
||||
_tx, ok := pr.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Project is not a transactional entity")
|
||||
}
|
||||
pr.config.driver = _tx.drv
|
||||
return pr
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (pr *Project) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Project(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", pr.ID))
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(pr.Name)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Projects is a parsable slice of Project.
|
||||
type Projects []*Project
|
||||
82
ent/project/project.go
Normal file
82
ent/project/project.go
Normal file
@ -0,0 +1,82 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package project
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the project type in the database.
|
||||
Label = "project"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// EdgeTeam holds the string denoting the team edge name in mutations.
|
||||
EdgeTeam = "team"
|
||||
// Table holds the table name of the project in the database.
|
||||
Table = "projects"
|
||||
// TeamTable is the table that holds the team relation/edge.
|
||||
TeamTable = "projects"
|
||||
// TeamInverseTable is the table name for the Team entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "team" package.
|
||||
TeamInverseTable = "teams"
|
||||
// TeamColumn is the table column denoting the team relation/edge.
|
||||
TeamColumn = "team_projects"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for project fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldName,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "projects"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"team_projects",
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Project queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTeamField orders the results by team field.
|
||||
func ByTeamField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newTeamStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newTeamStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(TeamInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, TeamTable, TeamColumn),
|
||||
)
|
||||
}
|
||||
163
ent/project/where.go
Normal file
163
ent/project/where.go
Normal file
@ -0,0 +1,163 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package project
|
||||
|
||||
import (
|
||||
"portfolio-backend/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Project {
|
||||
return predicate.Project(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Project {
|
||||
return predicate.Project(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Project {
|
||||
return predicate.Project(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Project {
|
||||
return predicate.Project(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Project {
|
||||
return predicate.Project(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Project {
|
||||
return predicate.Project(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Project {
|
||||
return predicate.Project(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Project {
|
||||
return predicate.Project(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Project {
|
||||
return predicate.Project(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.Project {
|
||||
return predicate.Project(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.Project {
|
||||
return predicate.Project(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.Project {
|
||||
return predicate.Project(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// HasTeam applies the HasEdge predicate on the "team" edge.
|
||||
func HasTeam() predicate.Project {
|
||||
return predicate.Project(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, TeamTable, TeamColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasTeamWith applies the HasEdge predicate on the "team" edge with a given conditions (other predicates).
|
||||
func HasTeamWith(preds ...predicate.Team) predicate.Project {
|
||||
return predicate.Project(func(s *sql.Selector) {
|
||||
step := newTeamStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Project) predicate.Project {
|
||||
return predicate.Project(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Project) predicate.Project {
|
||||
return predicate.Project(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Project) predicate.Project {
|
||||
return predicate.Project(sql.NotPredicates(p))
|
||||
}
|
||||
220
ent/project_create.go
Normal file
220
ent/project_create.go
Normal file
@ -0,0 +1,220 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"portfolio-backend/ent/project"
|
||||
"portfolio-backend/ent/team"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ProjectCreate is the builder for creating a Project entity.
|
||||
type ProjectCreate struct {
|
||||
config
|
||||
mutation *ProjectMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (pc *ProjectCreate) SetName(s string) *ProjectCreate {
|
||||
pc.mutation.SetName(s)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetTeamID sets the "team" edge to the Team entity by ID.
|
||||
func (pc *ProjectCreate) SetTeamID(id int) *ProjectCreate {
|
||||
pc.mutation.SetTeamID(id)
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetNillableTeamID sets the "team" edge to the Team entity by ID if the given value is not nil.
|
||||
func (pc *ProjectCreate) SetNillableTeamID(id *int) *ProjectCreate {
|
||||
if id != nil {
|
||||
pc = pc.SetTeamID(*id)
|
||||
}
|
||||
return pc
|
||||
}
|
||||
|
||||
// SetTeam sets the "team" edge to the Team entity.
|
||||
func (pc *ProjectCreate) SetTeam(t *Team) *ProjectCreate {
|
||||
return pc.SetTeamID(t.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the ProjectMutation object of the builder.
|
||||
func (pc *ProjectCreate) Mutation() *ProjectMutation {
|
||||
return pc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Project in the database.
|
||||
func (pc *ProjectCreate) Save(ctx context.Context) (*Project, error) {
|
||||
return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (pc *ProjectCreate) SaveX(ctx context.Context) *Project {
|
||||
v, err := pc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (pc *ProjectCreate) Exec(ctx context.Context) error {
|
||||
_, err := pc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (pc *ProjectCreate) ExecX(ctx context.Context) {
|
||||
if err := pc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (pc *ProjectCreate) check() error {
|
||||
if _, ok := pc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Project.name"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pc *ProjectCreate) sqlSave(ctx context.Context) (*Project, error) {
|
||||
if err := pc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := pc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, pc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
pc.mutation.id = &_node.ID
|
||||
pc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (pc *ProjectCreate) createSpec() (*Project, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Project{config: pc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(project.Table, sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := pc.mutation.Name(); ok {
|
||||
_spec.SetField(project.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if nodes := pc.mutation.TeamIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: project.TeamTable,
|
||||
Columns: []string{project.TeamColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.team_projects = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// ProjectCreateBulk is the builder for creating many Project entities in bulk.
|
||||
type ProjectCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*ProjectCreate
|
||||
}
|
||||
|
||||
// Save creates the Project entities in the database.
|
||||
func (pcb *ProjectCreateBulk) Save(ctx context.Context) ([]*Project, error) {
|
||||
if pcb.err != nil {
|
||||
return nil, pcb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(pcb.builders))
|
||||
nodes := make([]*Project, len(pcb.builders))
|
||||
mutators := make([]Mutator, len(pcb.builders))
|
||||
for i := range pcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := pcb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*ProjectMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, pcb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, pcb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, pcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (pcb *ProjectCreateBulk) SaveX(ctx context.Context) []*Project {
|
||||
v, err := pcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (pcb *ProjectCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := pcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (pcb *ProjectCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := pcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
88
ent/project_delete.go
Normal file
88
ent/project_delete.go
Normal file
@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"portfolio-backend/ent/predicate"
|
||||
"portfolio-backend/ent/project"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ProjectDelete is the builder for deleting a Project entity.
|
||||
type ProjectDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ProjectMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ProjectDelete builder.
|
||||
func (pd *ProjectDelete) Where(ps ...predicate.Project) *ProjectDelete {
|
||||
pd.mutation.Where(ps...)
|
||||
return pd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (pd *ProjectDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (pd *ProjectDelete) ExecX(ctx context.Context) int {
|
||||
n, err := pd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (pd *ProjectDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(project.Table, sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt))
|
||||
if ps := pd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, pd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
pd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ProjectDeleteOne is the builder for deleting a single Project entity.
|
||||
type ProjectDeleteOne struct {
|
||||
pd *ProjectDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ProjectDelete builder.
|
||||
func (pdo *ProjectDeleteOne) Where(ps ...predicate.Project) *ProjectDeleteOne {
|
||||
pdo.pd.mutation.Where(ps...)
|
||||
return pdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (pdo *ProjectDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := pdo.pd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{project.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (pdo *ProjectDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := pdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
613
ent/project_query.go
Normal file
613
ent/project_query.go
Normal file
@ -0,0 +1,613 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"portfolio-backend/ent/predicate"
|
||||
"portfolio-backend/ent/project"
|
||||
"portfolio-backend/ent/team"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ProjectQuery is the builder for querying Project entities.
|
||||
type ProjectQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []project.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Project
|
||||
withTeam *TeamQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the ProjectQuery builder.
|
||||
func (pq *ProjectQuery) Where(ps ...predicate.Project) *ProjectQuery {
|
||||
pq.predicates = append(pq.predicates, ps...)
|
||||
return pq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (pq *ProjectQuery) Limit(limit int) *ProjectQuery {
|
||||
pq.ctx.Limit = &limit
|
||||
return pq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (pq *ProjectQuery) Offset(offset int) *ProjectQuery {
|
||||
pq.ctx.Offset = &offset
|
||||
return pq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (pq *ProjectQuery) Unique(unique bool) *ProjectQuery {
|
||||
pq.ctx.Unique = &unique
|
||||
return pq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (pq *ProjectQuery) Order(o ...project.OrderOption) *ProjectQuery {
|
||||
pq.order = append(pq.order, o...)
|
||||
return pq
|
||||
}
|
||||
|
||||
// QueryTeam chains the current query on the "team" edge.
|
||||
func (pq *ProjectQuery) QueryTeam() *TeamQuery {
|
||||
query := (&TeamClient{config: pq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := pq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(project.Table, project.FieldID, selector),
|
||||
sqlgraph.To(team.Table, team.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, project.TeamTable, project.TeamColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(pq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Project entity from the query.
|
||||
// Returns a *NotFoundError when no Project was found.
|
||||
func (pq *ProjectQuery) First(ctx context.Context) (*Project, error) {
|
||||
nodes, err := pq.Limit(1).All(setContextOp(ctx, pq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{project.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (pq *ProjectQuery) FirstX(ctx context.Context) *Project {
|
||||
node, err := pq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Project ID from the query.
|
||||
// Returns a *NotFoundError when no Project ID was found.
|
||||
func (pq *ProjectQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = pq.Limit(1).IDs(setContextOp(ctx, pq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{project.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (pq *ProjectQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := pq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Project entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Project entity is found.
|
||||
// Returns a *NotFoundError when no Project entities are found.
|
||||
func (pq *ProjectQuery) Only(ctx context.Context) (*Project, error) {
|
||||
nodes, err := pq.Limit(2).All(setContextOp(ctx, pq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{project.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{project.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (pq *ProjectQuery) OnlyX(ctx context.Context) *Project {
|
||||
node, err := pq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Project ID in the query.
|
||||
// Returns a *NotSingularError when more than one Project ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (pq *ProjectQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = pq.Limit(2).IDs(setContextOp(ctx, pq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{project.Label}
|
||||
default:
|
||||
err = &NotSingularError{project.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (pq *ProjectQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := pq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Projects.
|
||||
func (pq *ProjectQuery) All(ctx context.Context) ([]*Project, error) {
|
||||
ctx = setContextOp(ctx, pq.ctx, "All")
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Project, *ProjectQuery]()
|
||||
return withInterceptors[[]*Project](ctx, pq, qr, pq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (pq *ProjectQuery) AllX(ctx context.Context) []*Project {
|
||||
nodes, err := pq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Project IDs.
|
||||
func (pq *ProjectQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if pq.ctx.Unique == nil && pq.path != nil {
|
||||
pq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, pq.ctx, "IDs")
|
||||
if err = pq.Select(project.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (pq *ProjectQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := pq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (pq *ProjectQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, pq.ctx, "Count")
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, pq, querierCount[*ProjectQuery](), pq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (pq *ProjectQuery) CountX(ctx context.Context) int {
|
||||
count, err := pq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (pq *ProjectQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, pq.ctx, "Exist")
|
||||
switch _, err := pq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (pq *ProjectQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := pq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the ProjectQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (pq *ProjectQuery) Clone() *ProjectQuery {
|
||||
if pq == nil {
|
||||
return nil
|
||||
}
|
||||
return &ProjectQuery{
|
||||
config: pq.config,
|
||||
ctx: pq.ctx.Clone(),
|
||||
order: append([]project.OrderOption{}, pq.order...),
|
||||
inters: append([]Interceptor{}, pq.inters...),
|
||||
predicates: append([]predicate.Project{}, pq.predicates...),
|
||||
withTeam: pq.withTeam.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: pq.sql.Clone(),
|
||||
path: pq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithTeam tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "team" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (pq *ProjectQuery) WithTeam(opts ...func(*TeamQuery)) *ProjectQuery {
|
||||
query := (&TeamClient{config: pq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
pq.withTeam = query
|
||||
return pq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Project.Query().
|
||||
// GroupBy(project.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (pq *ProjectQuery) GroupBy(field string, fields ...string) *ProjectGroupBy {
|
||||
pq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &ProjectGroupBy{build: pq}
|
||||
grbuild.flds = &pq.ctx.Fields
|
||||
grbuild.label = project.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Project.Query().
|
||||
// Select(project.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
func (pq *ProjectQuery) Select(fields ...string) *ProjectSelect {
|
||||
pq.ctx.Fields = append(pq.ctx.Fields, fields...)
|
||||
sbuild := &ProjectSelect{ProjectQuery: pq}
|
||||
sbuild.label = project.Label
|
||||
sbuild.flds, sbuild.scan = &pq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a ProjectSelect configured with the given aggregations.
|
||||
func (pq *ProjectQuery) Aggregate(fns ...AggregateFunc) *ProjectSelect {
|
||||
return pq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (pq *ProjectQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range pq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, pq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range pq.ctx.Fields {
|
||||
if !project.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if pq.path != nil {
|
||||
prev, err := pq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pq *ProjectQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Project, error) {
|
||||
var (
|
||||
nodes = []*Project{}
|
||||
withFKs = pq.withFKs
|
||||
_spec = pq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
pq.withTeam != nil,
|
||||
}
|
||||
)
|
||||
if pq.withTeam != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, project.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Project).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Project{config: pq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, pq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := pq.withTeam; query != nil {
|
||||
if err := pq.loadTeam(ctx, query, nodes, nil,
|
||||
func(n *Project, e *Team) { n.Edges.Team = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (pq *ProjectQuery) loadTeam(ctx context.Context, query *TeamQuery, nodes []*Project, init func(*Project), assign func(*Project, *Team)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Project)
|
||||
for i := range nodes {
|
||||
if nodes[i].team_projects == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].team_projects
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(team.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "team_projects" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pq *ProjectQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := pq.querySpec()
|
||||
_spec.Node.Columns = pq.ctx.Fields
|
||||
if len(pq.ctx.Fields) > 0 {
|
||||
_spec.Unique = pq.ctx.Unique != nil && *pq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, pq.driver, _spec)
|
||||
}
|
||||
|
||||
func (pq *ProjectQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(project.Table, project.Columns, sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt))
|
||||
_spec.From = pq.sql
|
||||
if unique := pq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if pq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := pq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, project.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != project.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := pq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := pq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := pq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := pq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (pq *ProjectQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(pq.driver.Dialect())
|
||||
t1 := builder.Table(project.Table)
|
||||
columns := pq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = project.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if pq.sql != nil {
|
||||
selector = pq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if pq.ctx.Unique != nil && *pq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range pq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range pq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := pq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := pq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ProjectGroupBy is the group-by builder for Project entities.
|
||||
type ProjectGroupBy struct {
|
||||
selector
|
||||
build *ProjectQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (pgb *ProjectGroupBy) Aggregate(fns ...AggregateFunc) *ProjectGroupBy {
|
||||
pgb.fns = append(pgb.fns, fns...)
|
||||
return pgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (pgb *ProjectGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, pgb.build.ctx, "GroupBy")
|
||||
if err := pgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*ProjectQuery, *ProjectGroupBy](ctx, pgb.build, pgb, pgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (pgb *ProjectGroupBy) sqlScan(ctx context.Context, root *ProjectQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(pgb.fns))
|
||||
for _, fn := range pgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*pgb.flds)+len(pgb.fns))
|
||||
for _, f := range *pgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*pgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := pgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// ProjectSelect is the builder for selecting fields of Project entities.
|
||||
type ProjectSelect struct {
|
||||
*ProjectQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ps *ProjectSelect) Aggregate(fns ...AggregateFunc) *ProjectSelect {
|
||||
ps.fns = append(ps.fns, fns...)
|
||||
return ps
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ps *ProjectSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ps.ctx, "Select")
|
||||
if err := ps.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*ProjectQuery, *ProjectSelect](ctx, ps.ProjectQuery, ps, ps.inters, v)
|
||||
}
|
||||
|
||||
func (ps *ProjectSelect) sqlScan(ctx context.Context, root *ProjectQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ps.fns))
|
||||
for _, fn := range ps.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ps.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ps.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
318
ent/project_update.go
Normal file
318
ent/project_update.go
Normal file
@ -0,0 +1,318 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"portfolio-backend/ent/predicate"
|
||||
"portfolio-backend/ent/project"
|
||||
"portfolio-backend/ent/team"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ProjectUpdate is the builder for updating Project entities.
|
||||
type ProjectUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ProjectMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ProjectUpdate builder.
|
||||
func (pu *ProjectUpdate) Where(ps ...predicate.Project) *ProjectUpdate {
|
||||
pu.mutation.Where(ps...)
|
||||
return pu
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (pu *ProjectUpdate) SetName(s string) *ProjectUpdate {
|
||||
pu.mutation.SetName(s)
|
||||
return pu
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (pu *ProjectUpdate) SetNillableName(s *string) *ProjectUpdate {
|
||||
if s != nil {
|
||||
pu.SetName(*s)
|
||||
}
|
||||
return pu
|
||||
}
|
||||
|
||||
// SetTeamID sets the "team" edge to the Team entity by ID.
|
||||
func (pu *ProjectUpdate) SetTeamID(id int) *ProjectUpdate {
|
||||
pu.mutation.SetTeamID(id)
|
||||
return pu
|
||||
}
|
||||
|
||||
// SetNillableTeamID sets the "team" edge to the Team entity by ID if the given value is not nil.
|
||||
func (pu *ProjectUpdate) SetNillableTeamID(id *int) *ProjectUpdate {
|
||||
if id != nil {
|
||||
pu = pu.SetTeamID(*id)
|
||||
}
|
||||
return pu
|
||||
}
|
||||
|
||||
// SetTeam sets the "team" edge to the Team entity.
|
||||
func (pu *ProjectUpdate) SetTeam(t *Team) *ProjectUpdate {
|
||||
return pu.SetTeamID(t.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the ProjectMutation object of the builder.
|
||||
func (pu *ProjectUpdate) Mutation() *ProjectMutation {
|
||||
return pu.mutation
|
||||
}
|
||||
|
||||
// ClearTeam clears the "team" edge to the Team entity.
|
||||
func (pu *ProjectUpdate) ClearTeam() *ProjectUpdate {
|
||||
pu.mutation.ClearTeam()
|
||||
return pu
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (pu *ProjectUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (pu *ProjectUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := pu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (pu *ProjectUpdate) Exec(ctx context.Context) error {
|
||||
_, err := pu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (pu *ProjectUpdate) ExecX(ctx context.Context) {
|
||||
if err := pu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (pu *ProjectUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(project.Table, project.Columns, sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt))
|
||||
if ps := pu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := pu.mutation.Name(); ok {
|
||||
_spec.SetField(project.FieldName, field.TypeString, value)
|
||||
}
|
||||
if pu.mutation.TeamCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: project.TeamTable,
|
||||
Columns: []string{project.TeamColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := pu.mutation.TeamIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: project.TeamTable,
|
||||
Columns: []string{project.TeamColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{project.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
pu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// ProjectUpdateOne is the builder for updating a single Project entity.
|
||||
type ProjectUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *ProjectMutation
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (puo *ProjectUpdateOne) SetName(s string) *ProjectUpdateOne {
|
||||
puo.mutation.SetName(s)
|
||||
return puo
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (puo *ProjectUpdateOne) SetNillableName(s *string) *ProjectUpdateOne {
|
||||
if s != nil {
|
||||
puo.SetName(*s)
|
||||
}
|
||||
return puo
|
||||
}
|
||||
|
||||
// SetTeamID sets the "team" edge to the Team entity by ID.
|
||||
func (puo *ProjectUpdateOne) SetTeamID(id int) *ProjectUpdateOne {
|
||||
puo.mutation.SetTeamID(id)
|
||||
return puo
|
||||
}
|
||||
|
||||
// SetNillableTeamID sets the "team" edge to the Team entity by ID if the given value is not nil.
|
||||
func (puo *ProjectUpdateOne) SetNillableTeamID(id *int) *ProjectUpdateOne {
|
||||
if id != nil {
|
||||
puo = puo.SetTeamID(*id)
|
||||
}
|
||||
return puo
|
||||
}
|
||||
|
||||
// SetTeam sets the "team" edge to the Team entity.
|
||||
func (puo *ProjectUpdateOne) SetTeam(t *Team) *ProjectUpdateOne {
|
||||
return puo.SetTeamID(t.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the ProjectMutation object of the builder.
|
||||
func (puo *ProjectUpdateOne) Mutation() *ProjectMutation {
|
||||
return puo.mutation
|
||||
}
|
||||
|
||||
// ClearTeam clears the "team" edge to the Team entity.
|
||||
func (puo *ProjectUpdateOne) ClearTeam() *ProjectUpdateOne {
|
||||
puo.mutation.ClearTeam()
|
||||
return puo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ProjectUpdate builder.
|
||||
func (puo *ProjectUpdateOne) Where(ps ...predicate.Project) *ProjectUpdateOne {
|
||||
puo.mutation.Where(ps...)
|
||||
return puo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (puo *ProjectUpdateOne) Select(field string, fields ...string) *ProjectUpdateOne {
|
||||
puo.fields = append([]string{field}, fields...)
|
||||
return puo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Project entity.
|
||||
func (puo *ProjectUpdateOne) Save(ctx context.Context) (*Project, error) {
|
||||
return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (puo *ProjectUpdateOne) SaveX(ctx context.Context) *Project {
|
||||
node, err := puo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (puo *ProjectUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := puo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (puo *ProjectUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := puo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (puo *ProjectUpdateOne) sqlSave(ctx context.Context) (_node *Project, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(project.Table, project.Columns, sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt))
|
||||
id, ok := puo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Project.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := puo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, project.FieldID)
|
||||
for _, f := range fields {
|
||||
if !project.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != project.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := puo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := puo.mutation.Name(); ok {
|
||||
_spec.SetField(project.FieldName, field.TypeString, value)
|
||||
}
|
||||
if puo.mutation.TeamCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: project.TeamTable,
|
||||
Columns: []string{project.TeamColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := puo.mutation.TeamIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: project.TeamTable,
|
||||
Columns: []string{project.TeamColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Project{config: puo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{project.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
puo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
29
ent/schema/project.go
Normal file
29
ent/schema/project.go
Normal file
@ -0,0 +1,29 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Project holds the schema definition for the Project entity.
|
||||
type Project struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Project.
|
||||
func (Project) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Project.
|
||||
func (Project) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("team", Team.Type).
|
||||
Ref("projects").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
26
ent/schema/team.go
Normal file
26
ent/schema/team.go
Normal file
@ -0,0 +1,26 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Team holds the schema definition for the Team entity.
|
||||
type Team struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Team.
|
||||
func (Team) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Team.
|
||||
func (Team) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("projects", Project.Type),
|
||||
}
|
||||
}
|
||||
129
ent/team.go
Normal file
129
ent/team.go
Normal file
@ -0,0 +1,129 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"portfolio-backend/ent/team"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Team is the model entity for the Team schema.
|
||||
type Team struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the TeamQuery when eager-loading is set.
|
||||
Edges TeamEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// TeamEdges holds the relations/edges for other nodes in the graph.
|
||||
type TeamEdges struct {
|
||||
// Projects holds the value of the projects edge.
|
||||
Projects []*Project `json:"projects,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// ProjectsOrErr returns the Projects value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e TeamEdges) ProjectsOrErr() ([]*Project, error) {
|
||||
if e.loadedTypes[0] {
|
||||
return e.Projects, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "projects"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Team) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case team.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case team.FieldName:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Team fields.
|
||||
func (t *Team) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case team.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
t.ID = int(value.Int64)
|
||||
case team.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
t.Name = value.String
|
||||
}
|
||||
default:
|
||||
t.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Team.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (t *Team) Value(name string) (ent.Value, error) {
|
||||
return t.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryProjects queries the "projects" edge of the Team entity.
|
||||
func (t *Team) QueryProjects() *ProjectQuery {
|
||||
return NewTeamClient(t.config).QueryProjects(t)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Team.
|
||||
// Note that you need to call Team.Unwrap() before calling this method if this Team
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (t *Team) Update() *TeamUpdateOne {
|
||||
return NewTeamClient(t.config).UpdateOne(t)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Team entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (t *Team) Unwrap() *Team {
|
||||
_tx, ok := t.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Team is not a transactional entity")
|
||||
}
|
||||
t.config.driver = _tx.drv
|
||||
return t
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (t *Team) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Team(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", t.ID))
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(t.Name)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Teams is a parsable slice of Team.
|
||||
type Teams []*Team
|
||||
78
ent/team/team.go
Normal file
78
ent/team/team.go
Normal file
@ -0,0 +1,78 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package team
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the team type in the database.
|
||||
Label = "team"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// EdgeProjects holds the string denoting the projects edge name in mutations.
|
||||
EdgeProjects = "projects"
|
||||
// Table holds the table name of the team in the database.
|
||||
Table = "teams"
|
||||
// ProjectsTable is the table that holds the projects relation/edge.
|
||||
ProjectsTable = "projects"
|
||||
// ProjectsInverseTable is the table name for the Project entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "project" package.
|
||||
ProjectsInverseTable = "projects"
|
||||
// ProjectsColumn is the table column denoting the projects relation/edge.
|
||||
ProjectsColumn = "team_projects"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for team fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldName,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Team queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByProjectsCount orders the results by projects count.
|
||||
func ByProjectsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newProjectsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByProjects orders the results by projects terms.
|
||||
func ByProjects(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newProjectsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newProjectsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(ProjectsInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, ProjectsTable, ProjectsColumn),
|
||||
)
|
||||
}
|
||||
163
ent/team/where.go
Normal file
163
ent/team/where.go
Normal file
@ -0,0 +1,163 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package team
|
||||
|
||||
import (
|
||||
"portfolio-backend/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Team {
|
||||
return predicate.Team(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Team {
|
||||
return predicate.Team(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Team {
|
||||
return predicate.Team(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Team {
|
||||
return predicate.Team(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Team {
|
||||
return predicate.Team(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Team {
|
||||
return predicate.Team(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Team {
|
||||
return predicate.Team(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Team {
|
||||
return predicate.Team(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Team {
|
||||
return predicate.Team(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.Team {
|
||||
return predicate.Team(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.Team {
|
||||
return predicate.Team(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.Team {
|
||||
return predicate.Team(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// HasProjects applies the HasEdge predicate on the "projects" edge.
|
||||
func HasProjects() predicate.Team {
|
||||
return predicate.Team(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, ProjectsTable, ProjectsColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasProjectsWith applies the HasEdge predicate on the "projects" edge with a given conditions (other predicates).
|
||||
func HasProjectsWith(preds ...predicate.Project) predicate.Team {
|
||||
return predicate.Team(func(s *sql.Selector) {
|
||||
step := newProjectsStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Team) predicate.Team {
|
||||
return predicate.Team(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Team) predicate.Team {
|
||||
return predicate.Team(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Team) predicate.Team {
|
||||
return predicate.Team(sql.NotPredicates(p))
|
||||
}
|
||||
215
ent/team_create.go
Normal file
215
ent/team_create.go
Normal file
@ -0,0 +1,215 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"portfolio-backend/ent/project"
|
||||
"portfolio-backend/ent/team"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// TeamCreate is the builder for creating a Team entity.
|
||||
type TeamCreate struct {
|
||||
config
|
||||
mutation *TeamMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (tc *TeamCreate) SetName(s string) *TeamCreate {
|
||||
tc.mutation.SetName(s)
|
||||
return tc
|
||||
}
|
||||
|
||||
// AddProjectIDs adds the "projects" edge to the Project entity by IDs.
|
||||
func (tc *TeamCreate) AddProjectIDs(ids ...int) *TeamCreate {
|
||||
tc.mutation.AddProjectIDs(ids...)
|
||||
return tc
|
||||
}
|
||||
|
||||
// AddProjects adds the "projects" edges to the Project entity.
|
||||
func (tc *TeamCreate) AddProjects(p ...*Project) *TeamCreate {
|
||||
ids := make([]int, len(p))
|
||||
for i := range p {
|
||||
ids[i] = p[i].ID
|
||||
}
|
||||
return tc.AddProjectIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the TeamMutation object of the builder.
|
||||
func (tc *TeamCreate) Mutation() *TeamMutation {
|
||||
return tc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Team in the database.
|
||||
func (tc *TeamCreate) Save(ctx context.Context) (*Team, error) {
|
||||
return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (tc *TeamCreate) SaveX(ctx context.Context) *Team {
|
||||
v, err := tc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (tc *TeamCreate) Exec(ctx context.Context) error {
|
||||
_, err := tc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tc *TeamCreate) ExecX(ctx context.Context) {
|
||||
if err := tc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (tc *TeamCreate) check() error {
|
||||
if _, ok := tc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Team.name"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tc *TeamCreate) sqlSave(ctx context.Context) (*Team, error) {
|
||||
if err := tc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := tc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, tc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
tc.mutation.id = &_node.ID
|
||||
tc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (tc *TeamCreate) createSpec() (*Team, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Team{config: tc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(team.Table, sqlgraph.NewFieldSpec(team.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := tc.mutation.Name(); ok {
|
||||
_spec.SetField(team.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if nodes := tc.mutation.ProjectsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: team.ProjectsTable,
|
||||
Columns: []string{team.ProjectsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// TeamCreateBulk is the builder for creating many Team entities in bulk.
|
||||
type TeamCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*TeamCreate
|
||||
}
|
||||
|
||||
// Save creates the Team entities in the database.
|
||||
func (tcb *TeamCreateBulk) Save(ctx context.Context) ([]*Team, error) {
|
||||
if tcb.err != nil {
|
||||
return nil, tcb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(tcb.builders))
|
||||
nodes := make([]*Team, len(tcb.builders))
|
||||
mutators := make([]Mutator, len(tcb.builders))
|
||||
for i := range tcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := tcb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*TeamMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, tcb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, tcb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, tcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tcb *TeamCreateBulk) SaveX(ctx context.Context) []*Team {
|
||||
v, err := tcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (tcb *TeamCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := tcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tcb *TeamCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := tcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
88
ent/team_delete.go
Normal file
88
ent/team_delete.go
Normal file
@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"portfolio-backend/ent/predicate"
|
||||
"portfolio-backend/ent/team"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// TeamDelete is the builder for deleting a Team entity.
|
||||
type TeamDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *TeamMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TeamDelete builder.
|
||||
func (td *TeamDelete) Where(ps ...predicate.Team) *TeamDelete {
|
||||
td.mutation.Where(ps...)
|
||||
return td
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (td *TeamDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, td.sqlExec, td.mutation, td.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (td *TeamDelete) ExecX(ctx context.Context) int {
|
||||
n, err := td.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (td *TeamDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(team.Table, sqlgraph.NewFieldSpec(team.FieldID, field.TypeInt))
|
||||
if ps := td.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, td.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
td.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// TeamDeleteOne is the builder for deleting a single Team entity.
|
||||
type TeamDeleteOne struct {
|
||||
td *TeamDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TeamDelete builder.
|
||||
func (tdo *TeamDeleteOne) Where(ps ...predicate.Team) *TeamDeleteOne {
|
||||
tdo.td.mutation.Where(ps...)
|
||||
return tdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (tdo *TeamDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := tdo.td.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{team.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tdo *TeamDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := tdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
606
ent/team_query.go
Normal file
606
ent/team_query.go
Normal file
@ -0,0 +1,606 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"math"
|
||||
"portfolio-backend/ent/predicate"
|
||||
"portfolio-backend/ent/project"
|
||||
"portfolio-backend/ent/team"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// TeamQuery is the builder for querying Team entities.
|
||||
type TeamQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []team.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Team
|
||||
withProjects *ProjectQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the TeamQuery builder.
|
||||
func (tq *TeamQuery) Where(ps ...predicate.Team) *TeamQuery {
|
||||
tq.predicates = append(tq.predicates, ps...)
|
||||
return tq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (tq *TeamQuery) Limit(limit int) *TeamQuery {
|
||||
tq.ctx.Limit = &limit
|
||||
return tq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (tq *TeamQuery) Offset(offset int) *TeamQuery {
|
||||
tq.ctx.Offset = &offset
|
||||
return tq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (tq *TeamQuery) Unique(unique bool) *TeamQuery {
|
||||
tq.ctx.Unique = &unique
|
||||
return tq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (tq *TeamQuery) Order(o ...team.OrderOption) *TeamQuery {
|
||||
tq.order = append(tq.order, o...)
|
||||
return tq
|
||||
}
|
||||
|
||||
// QueryProjects chains the current query on the "projects" edge.
|
||||
func (tq *TeamQuery) QueryProjects() *ProjectQuery {
|
||||
query := (&ProjectClient{config: tq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := tq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := tq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(team.Table, team.FieldID, selector),
|
||||
sqlgraph.To(project.Table, project.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, team.ProjectsTable, team.ProjectsColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(tq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Team entity from the query.
|
||||
// Returns a *NotFoundError when no Team was found.
|
||||
func (tq *TeamQuery) First(ctx context.Context) (*Team, error) {
|
||||
nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{team.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (tq *TeamQuery) FirstX(ctx context.Context) *Team {
|
||||
node, err := tq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Team ID from the query.
|
||||
// Returns a *NotFoundError when no Team ID was found.
|
||||
func (tq *TeamQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{team.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (tq *TeamQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := tq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Team entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Team entity is found.
|
||||
// Returns a *NotFoundError when no Team entities are found.
|
||||
func (tq *TeamQuery) Only(ctx context.Context) (*Team, error) {
|
||||
nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{team.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{team.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (tq *TeamQuery) OnlyX(ctx context.Context) *Team {
|
||||
node, err := tq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Team ID in the query.
|
||||
// Returns a *NotSingularError when more than one Team ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (tq *TeamQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{team.Label}
|
||||
default:
|
||||
err = &NotSingularError{team.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (tq *TeamQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := tq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Teams.
|
||||
func (tq *TeamQuery) All(ctx context.Context) ([]*Team, error) {
|
||||
ctx = setContextOp(ctx, tq.ctx, "All")
|
||||
if err := tq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Team, *TeamQuery]()
|
||||
return withInterceptors[[]*Team](ctx, tq, qr, tq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (tq *TeamQuery) AllX(ctx context.Context) []*Team {
|
||||
nodes, err := tq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Team IDs.
|
||||
func (tq *TeamQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if tq.ctx.Unique == nil && tq.path != nil {
|
||||
tq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, tq.ctx, "IDs")
|
||||
if err = tq.Select(team.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (tq *TeamQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := tq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (tq *TeamQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, tq.ctx, "Count")
|
||||
if err := tq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, tq, querierCount[*TeamQuery](), tq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (tq *TeamQuery) CountX(ctx context.Context) int {
|
||||
count, err := tq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (tq *TeamQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, tq.ctx, "Exist")
|
||||
switch _, err := tq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (tq *TeamQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := tq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the TeamQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (tq *TeamQuery) Clone() *TeamQuery {
|
||||
if tq == nil {
|
||||
return nil
|
||||
}
|
||||
return &TeamQuery{
|
||||
config: tq.config,
|
||||
ctx: tq.ctx.Clone(),
|
||||
order: append([]team.OrderOption{}, tq.order...),
|
||||
inters: append([]Interceptor{}, tq.inters...),
|
||||
predicates: append([]predicate.Team{}, tq.predicates...),
|
||||
withProjects: tq.withProjects.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: tq.sql.Clone(),
|
||||
path: tq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithProjects tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "projects" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (tq *TeamQuery) WithProjects(opts ...func(*ProjectQuery)) *TeamQuery {
|
||||
query := (&ProjectClient{config: tq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
tq.withProjects = query
|
||||
return tq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Team.Query().
|
||||
// GroupBy(team.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (tq *TeamQuery) GroupBy(field string, fields ...string) *TeamGroupBy {
|
||||
tq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &TeamGroupBy{build: tq}
|
||||
grbuild.flds = &tq.ctx.Fields
|
||||
grbuild.label = team.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Team.Query().
|
||||
// Select(team.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
func (tq *TeamQuery) Select(fields ...string) *TeamSelect {
|
||||
tq.ctx.Fields = append(tq.ctx.Fields, fields...)
|
||||
sbuild := &TeamSelect{TeamQuery: tq}
|
||||
sbuild.label = team.Label
|
||||
sbuild.flds, sbuild.scan = &tq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a TeamSelect configured with the given aggregations.
|
||||
func (tq *TeamQuery) Aggregate(fns ...AggregateFunc) *TeamSelect {
|
||||
return tq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (tq *TeamQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range tq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, tq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range tq.ctx.Fields {
|
||||
if !team.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if tq.path != nil {
|
||||
prev, err := tq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tq *TeamQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Team, error) {
|
||||
var (
|
||||
nodes = []*Team{}
|
||||
_spec = tq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
tq.withProjects != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Team).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Team{config: tq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, tq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := tq.withProjects; query != nil {
|
||||
if err := tq.loadProjects(ctx, query, nodes,
|
||||
func(n *Team) { n.Edges.Projects = []*Project{} },
|
||||
func(n *Team, e *Project) { n.Edges.Projects = append(n.Edges.Projects, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (tq *TeamQuery) loadProjects(ctx context.Context, query *ProjectQuery, nodes []*Team, init func(*Team), assign func(*Team, *Project)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*Team)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.Project(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(team.ProjectsColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.team_projects
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "team_projects" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "team_projects" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tq *TeamQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := tq.querySpec()
|
||||
_spec.Node.Columns = tq.ctx.Fields
|
||||
if len(tq.ctx.Fields) > 0 {
|
||||
_spec.Unique = tq.ctx.Unique != nil && *tq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, tq.driver, _spec)
|
||||
}
|
||||
|
||||
func (tq *TeamQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(team.Table, team.Columns, sqlgraph.NewFieldSpec(team.FieldID, field.TypeInt))
|
||||
_spec.From = tq.sql
|
||||
if unique := tq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if tq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := tq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, team.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != team.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := tq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := tq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := tq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := tq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (tq *TeamQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(tq.driver.Dialect())
|
||||
t1 := builder.Table(team.Table)
|
||||
columns := tq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = team.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if tq.sql != nil {
|
||||
selector = tq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if tq.ctx.Unique != nil && *tq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range tq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range tq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := tq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := tq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// TeamGroupBy is the group-by builder for Team entities.
|
||||
type TeamGroupBy struct {
|
||||
selector
|
||||
build *TeamQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (tgb *TeamGroupBy) Aggregate(fns ...AggregateFunc) *TeamGroupBy {
|
||||
tgb.fns = append(tgb.fns, fns...)
|
||||
return tgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (tgb *TeamGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, tgb.build.ctx, "GroupBy")
|
||||
if err := tgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*TeamQuery, *TeamGroupBy](ctx, tgb.build, tgb, tgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (tgb *TeamGroupBy) sqlScan(ctx context.Context, root *TeamQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(tgb.fns))
|
||||
for _, fn := range tgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*tgb.flds)+len(tgb.fns))
|
||||
for _, f := range *tgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*tgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := tgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// TeamSelect is the builder for selecting fields of Team entities.
|
||||
type TeamSelect struct {
|
||||
*TeamQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ts *TeamSelect) Aggregate(fns ...AggregateFunc) *TeamSelect {
|
||||
ts.fns = append(ts.fns, fns...)
|
||||
return ts
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ts *TeamSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ts.ctx, "Select")
|
||||
if err := ts.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*TeamQuery, *TeamSelect](ctx, ts.TeamQuery, ts, ts.inters, v)
|
||||
}
|
||||
|
||||
func (ts *TeamSelect) sqlScan(ctx context.Context, root *TeamQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ts.fns))
|
||||
for _, fn := range ts.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ts.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ts.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
372
ent/team_update.go
Normal file
372
ent/team_update.go
Normal file
@ -0,0 +1,372 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"portfolio-backend/ent/predicate"
|
||||
"portfolio-backend/ent/project"
|
||||
"portfolio-backend/ent/team"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// TeamUpdate is the builder for updating Team entities.
|
||||
type TeamUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *TeamMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TeamUpdate builder.
|
||||
func (tu *TeamUpdate) Where(ps ...predicate.Team) *TeamUpdate {
|
||||
tu.mutation.Where(ps...)
|
||||
return tu
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (tu *TeamUpdate) SetName(s string) *TeamUpdate {
|
||||
tu.mutation.SetName(s)
|
||||
return tu
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (tu *TeamUpdate) SetNillableName(s *string) *TeamUpdate {
|
||||
if s != nil {
|
||||
tu.SetName(*s)
|
||||
}
|
||||
return tu
|
||||
}
|
||||
|
||||
// AddProjectIDs adds the "projects" edge to the Project entity by IDs.
|
||||
func (tu *TeamUpdate) AddProjectIDs(ids ...int) *TeamUpdate {
|
||||
tu.mutation.AddProjectIDs(ids...)
|
||||
return tu
|
||||
}
|
||||
|
||||
// AddProjects adds the "projects" edges to the Project entity.
|
||||
func (tu *TeamUpdate) AddProjects(p ...*Project) *TeamUpdate {
|
||||
ids := make([]int, len(p))
|
||||
for i := range p {
|
||||
ids[i] = p[i].ID
|
||||
}
|
||||
return tu.AddProjectIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the TeamMutation object of the builder.
|
||||
func (tu *TeamUpdate) Mutation() *TeamMutation {
|
||||
return tu.mutation
|
||||
}
|
||||
|
||||
// ClearProjects clears all "projects" edges to the Project entity.
|
||||
func (tu *TeamUpdate) ClearProjects() *TeamUpdate {
|
||||
tu.mutation.ClearProjects()
|
||||
return tu
|
||||
}
|
||||
|
||||
// RemoveProjectIDs removes the "projects" edge to Project entities by IDs.
|
||||
func (tu *TeamUpdate) RemoveProjectIDs(ids ...int) *TeamUpdate {
|
||||
tu.mutation.RemoveProjectIDs(ids...)
|
||||
return tu
|
||||
}
|
||||
|
||||
// RemoveProjects removes "projects" edges to Project entities.
|
||||
func (tu *TeamUpdate) RemoveProjects(p ...*Project) *TeamUpdate {
|
||||
ids := make([]int, len(p))
|
||||
for i := range p {
|
||||
ids[i] = p[i].ID
|
||||
}
|
||||
return tu.RemoveProjectIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (tu *TeamUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tu *TeamUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := tu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (tu *TeamUpdate) Exec(ctx context.Context) error {
|
||||
_, err := tu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tu *TeamUpdate) ExecX(ctx context.Context) {
|
||||
if err := tu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (tu *TeamUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(team.Table, team.Columns, sqlgraph.NewFieldSpec(team.FieldID, field.TypeInt))
|
||||
if ps := tu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := tu.mutation.Name(); ok {
|
||||
_spec.SetField(team.FieldName, field.TypeString, value)
|
||||
}
|
||||
if tu.mutation.ProjectsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: team.ProjectsTable,
|
||||
Columns: []string{team.ProjectsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tu.mutation.RemovedProjectsIDs(); len(nodes) > 0 && !tu.mutation.ProjectsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: team.ProjectsTable,
|
||||
Columns: []string{team.ProjectsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tu.mutation.ProjectsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: team.ProjectsTable,
|
||||
Columns: []string{team.ProjectsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, tu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{team.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
tu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// TeamUpdateOne is the builder for updating a single Team entity.
|
||||
type TeamUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *TeamMutation
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (tuo *TeamUpdateOne) SetName(s string) *TeamUpdateOne {
|
||||
tuo.mutation.SetName(s)
|
||||
return tuo
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (tuo *TeamUpdateOne) SetNillableName(s *string) *TeamUpdateOne {
|
||||
if s != nil {
|
||||
tuo.SetName(*s)
|
||||
}
|
||||
return tuo
|
||||
}
|
||||
|
||||
// AddProjectIDs adds the "projects" edge to the Project entity by IDs.
|
||||
func (tuo *TeamUpdateOne) AddProjectIDs(ids ...int) *TeamUpdateOne {
|
||||
tuo.mutation.AddProjectIDs(ids...)
|
||||
return tuo
|
||||
}
|
||||
|
||||
// AddProjects adds the "projects" edges to the Project entity.
|
||||
func (tuo *TeamUpdateOne) AddProjects(p ...*Project) *TeamUpdateOne {
|
||||
ids := make([]int, len(p))
|
||||
for i := range p {
|
||||
ids[i] = p[i].ID
|
||||
}
|
||||
return tuo.AddProjectIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the TeamMutation object of the builder.
|
||||
func (tuo *TeamUpdateOne) Mutation() *TeamMutation {
|
||||
return tuo.mutation
|
||||
}
|
||||
|
||||
// ClearProjects clears all "projects" edges to the Project entity.
|
||||
func (tuo *TeamUpdateOne) ClearProjects() *TeamUpdateOne {
|
||||
tuo.mutation.ClearProjects()
|
||||
return tuo
|
||||
}
|
||||
|
||||
// RemoveProjectIDs removes the "projects" edge to Project entities by IDs.
|
||||
func (tuo *TeamUpdateOne) RemoveProjectIDs(ids ...int) *TeamUpdateOne {
|
||||
tuo.mutation.RemoveProjectIDs(ids...)
|
||||
return tuo
|
||||
}
|
||||
|
||||
// RemoveProjects removes "projects" edges to Project entities.
|
||||
func (tuo *TeamUpdateOne) RemoveProjects(p ...*Project) *TeamUpdateOne {
|
||||
ids := make([]int, len(p))
|
||||
for i := range p {
|
||||
ids[i] = p[i].ID
|
||||
}
|
||||
return tuo.RemoveProjectIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TeamUpdate builder.
|
||||
func (tuo *TeamUpdateOne) Where(ps ...predicate.Team) *TeamUpdateOne {
|
||||
tuo.mutation.Where(ps...)
|
||||
return tuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (tuo *TeamUpdateOne) Select(field string, fields ...string) *TeamUpdateOne {
|
||||
tuo.fields = append([]string{field}, fields...)
|
||||
return tuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Team entity.
|
||||
func (tuo *TeamUpdateOne) Save(ctx context.Context) (*Team, error) {
|
||||
return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tuo *TeamUpdateOne) SaveX(ctx context.Context) *Team {
|
||||
node, err := tuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (tuo *TeamUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := tuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tuo *TeamUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := tuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (tuo *TeamUpdateOne) sqlSave(ctx context.Context) (_node *Team, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(team.Table, team.Columns, sqlgraph.NewFieldSpec(team.FieldID, field.TypeInt))
|
||||
id, ok := tuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Team.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := tuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, team.FieldID)
|
||||
for _, f := range fields {
|
||||
if !team.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != team.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := tuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := tuo.mutation.Name(); ok {
|
||||
_spec.SetField(team.FieldName, field.TypeString, value)
|
||||
}
|
||||
if tuo.mutation.ProjectsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: team.ProjectsTable,
|
||||
Columns: []string{team.ProjectsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tuo.mutation.RemovedProjectsIDs(); len(nodes) > 0 && !tuo.mutation.ProjectsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: team.ProjectsTable,
|
||||
Columns: []string{team.ProjectsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tuo.mutation.ProjectsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: team.ProjectsTable,
|
||||
Columns: []string{team.ProjectsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Team{config: tuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, tuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{team.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
tuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@ -12,6 +12,10 @@ import (
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// Project is the client for interacting with the Project builders.
|
||||
Project *ProjectClient
|
||||
// Team is the client for interacting with the Team builders.
|
||||
Team *TeamClient
|
||||
// User is the client for interacting with the User builders.
|
||||
User *UserClient
|
||||
|
||||
@ -145,6 +149,8 @@ func (tx *Tx) Client() *Client {
|
||||
}
|
||||
|
||||
func (tx *Tx) init() {
|
||||
tx.Project = NewProjectClient(tx.config)
|
||||
tx.Team = NewTeamClient(tx.config)
|
||||
tx.User = NewUserClient(tx.config)
|
||||
}
|
||||
|
||||
@ -155,7 +161,7 @@ func (tx *Tx) init() {
|
||||
// of them in order to commit or rollback the transaction.
|
||||
//
|
||||
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||
// applies a query, for example: User.QueryXXX(), the query will be executed
|
||||
// applies a query, for example: Project.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
|
||||
12
go.sum
12
go.sum
@ -22,6 +22,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI=
|
||||
github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
@ -30,14 +32,22 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
|
||||
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/zclconf/go-cty v1.14.2 h1:kTG7lqmBou0Zkx35r6HJHUQTvaRPr5bIAf3AoHS0izI=
|
||||
@ -46,5 +56,7 @@ golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
|
||||
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
|
||||
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user