// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "log" "reflect" "tss-rocks-be/ent/migrate" "tss-rocks-be/ent/category" "tss-rocks-be/ent/categorycontent" "tss-rocks-be/ent/contributor" "tss-rocks-be/ent/contributorrole" "tss-rocks-be/ent/contributorsociallink" "tss-rocks-be/ent/daily" "tss-rocks-be/ent/dailycategory" "tss-rocks-be/ent/dailycategorycontent" "tss-rocks-be/ent/dailycontent" "tss-rocks-be/ent/media" "tss-rocks-be/ent/permission" "tss-rocks-be/ent/post" "tss-rocks-be/ent/postcontent" "tss-rocks-be/ent/postcontributor" "tss-rocks-be/ent/role" "tss-rocks-be/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. type Client struct { config // Schema is the client for creating, migrating and dropping schema. Schema *migrate.Schema // Category is the client for interacting with the Category builders. Category *CategoryClient // CategoryContent is the client for interacting with the CategoryContent builders. CategoryContent *CategoryContentClient // Contributor is the client for interacting with the Contributor builders. Contributor *ContributorClient // ContributorRole is the client for interacting with the ContributorRole builders. ContributorRole *ContributorRoleClient // ContributorSocialLink is the client for interacting with the ContributorSocialLink builders. ContributorSocialLink *ContributorSocialLinkClient // Daily is the client for interacting with the Daily builders. Daily *DailyClient // DailyCategory is the client for interacting with the DailyCategory builders. DailyCategory *DailyCategoryClient // DailyCategoryContent is the client for interacting with the DailyCategoryContent builders. DailyCategoryContent *DailyCategoryContentClient // DailyContent is the client for interacting with the DailyContent builders. DailyContent *DailyContentClient // Media is the client for interacting with the Media builders. Media *MediaClient // Permission is the client for interacting with the Permission builders. Permission *PermissionClient // Post is the client for interacting with the Post builders. Post *PostClient // PostContent is the client for interacting with the PostContent builders. PostContent *PostContentClient // PostContributor is the client for interacting with the PostContributor builders. PostContributor *PostContributorClient // Role is the client for interacting with the Role builders. Role *RoleClient // User is the client for interacting with the User builders. User *UserClient } // NewClient creates a new client configured with the given options. func NewClient(opts ...Option) *Client { client := &Client{config: newConfig(opts...)} client.init() return client } func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) c.Category = NewCategoryClient(c.config) c.CategoryContent = NewCategoryContentClient(c.config) c.Contributor = NewContributorClient(c.config) c.ContributorRole = NewContributorRoleClient(c.config) c.ContributorSocialLink = NewContributorSocialLinkClient(c.config) c.Daily = NewDailyClient(c.config) c.DailyCategory = NewDailyCategoryClient(c.config) c.DailyCategoryContent = NewDailyCategoryContentClient(c.config) c.DailyContent = NewDailyContentClient(c.config) c.Media = NewMediaClient(c.config) c.Permission = NewPermissionClient(c.config) c.Post = NewPostClient(c.config) c.PostContent = NewPostContentClient(c.config) c.PostContributor = NewPostContributorClient(c.config) c.Role = NewRoleClient(c.config) c.User = NewUserClient(c.config) } type ( // config is the configuration for the client and its builder. config struct { // driver used for executing database requests. driver dialect.Driver // debug enable a debug logging. debug bool // log used for logging on debug mode. log func(...any) // hooks to execute on mutations. hooks *hooks // interceptors to execute on queries. inters *inters } // Option function to configure the client. Option func(*config) ) // newConfig creates a new config for the client. func newConfig(opts ...Option) config { cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} cfg.options(opts...) return cfg } // options applies the options on the config object. func (c *config) options(opts ...Option) { for _, opt := range opts { opt(c) } if c.debug { c.driver = dialect.Debug(c.driver, c.log) } } // Debug enables debug logging on the ent.Driver. func Debug() Option { return func(c *config) { c.debug = true } } // Log sets the logging function for debug mode. func Log(fn func(...any)) Option { return func(c *config) { c.log = fn } } // Driver configures the client driver. func Driver(driver dialect.Driver) Option { return func(c *config) { c.driver = driver } } // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { switch driverName { case dialect.MySQL, dialect.Postgres, dialect.SQLite: drv, err := sql.Open(driverName, dataSourceName) if err != nil { return nil, err } return NewClient(append(options, Driver(drv))...), nil default: return nil, fmt.Errorf("unsupported driver: %q", driverName) } } // ErrTxStarted is returned when trying to start a new transaction from a transactional client. var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { return nil, fmt.Errorf("ent: starting a transaction: %w", err) } cfg := c.config cfg.driver = tx return &Tx{ ctx: ctx, config: cfg, Category: NewCategoryClient(cfg), CategoryContent: NewCategoryContentClient(cfg), Contributor: NewContributorClient(cfg), ContributorRole: NewContributorRoleClient(cfg), ContributorSocialLink: NewContributorSocialLinkClient(cfg), Daily: NewDailyClient(cfg), DailyCategory: NewDailyCategoryClient(cfg), DailyCategoryContent: NewDailyCategoryContentClient(cfg), DailyContent: NewDailyContentClient(cfg), Media: NewMediaClient(cfg), Permission: NewPermissionClient(cfg), Post: NewPostClient(cfg), PostContent: NewPostContentClient(cfg), PostContributor: NewPostContributorClient(cfg), Role: NewRoleClient(cfg), User: NewUserClient(cfg), }, nil } // BeginTx returns a transactional client with specified options. func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { return nil, errors.New("ent: cannot start a transaction within a transaction") } tx, err := c.driver.(interface { BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) }).BeginTx(ctx, opts) if err != nil { return nil, fmt.Errorf("ent: starting a transaction: %w", err) } cfg := c.config cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ ctx: ctx, config: cfg, Category: NewCategoryClient(cfg), CategoryContent: NewCategoryContentClient(cfg), Contributor: NewContributorClient(cfg), ContributorRole: NewContributorRoleClient(cfg), ContributorSocialLink: NewContributorSocialLinkClient(cfg), Daily: NewDailyClient(cfg), DailyCategory: NewDailyCategoryClient(cfg), DailyCategoryContent: NewDailyCategoryContentClient(cfg), DailyContent: NewDailyContentClient(cfg), Media: NewMediaClient(cfg), Permission: NewPermissionClient(cfg), Post: NewPostClient(cfg), PostContent: NewPostContentClient(cfg), PostContributor: NewPostContributorClient(cfg), Role: NewRoleClient(cfg), User: NewUserClient(cfg), }, nil } // Debug returns a new debug-client. It's used to get verbose logging on specific operations. // // client.Debug(). // Category. // Query(). // Count(ctx) func (c *Client) Debug() *Client { if c.debug { return c } cfg := c.config cfg.driver = dialect.Debug(c.driver, c.log) client := &Client{config: cfg} client.init() return client } // Close closes the database connection and prevents new queries from starting. func (c *Client) Close() error { return c.driver.Close() } // 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) { for _, n := range []interface{ Use(...Hook) }{ c.Category, c.CategoryContent, c.Contributor, c.ContributorRole, c.ContributorSocialLink, c.Daily, c.DailyCategory, c.DailyCategoryContent, c.DailyContent, c.Media, c.Permission, c.Post, c.PostContent, c.PostContributor, c.Role, c.User, } { n.Use(hooks...) } } // Intercept adds the query interceptors to all the entity clients. // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ c.Category, c.CategoryContent, c.Contributor, c.ContributorRole, c.ContributorSocialLink, c.Daily, c.DailyCategory, c.DailyCategoryContent, c.DailyContent, c.Media, c.Permission, c.Post, c.PostContent, c.PostContributor, c.Role, c.User, } { n.Intercept(interceptors...) } } // Mutate implements the ent.Mutator interface. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { switch m := m.(type) { case *CategoryMutation: return c.Category.mutate(ctx, m) case *CategoryContentMutation: return c.CategoryContent.mutate(ctx, m) case *ContributorMutation: return c.Contributor.mutate(ctx, m) case *ContributorRoleMutation: return c.ContributorRole.mutate(ctx, m) case *ContributorSocialLinkMutation: return c.ContributorSocialLink.mutate(ctx, m) case *DailyMutation: return c.Daily.mutate(ctx, m) case *DailyCategoryMutation: return c.DailyCategory.mutate(ctx, m) case *DailyCategoryContentMutation: return c.DailyCategoryContent.mutate(ctx, m) case *DailyContentMutation: return c.DailyContent.mutate(ctx, m) case *MediaMutation: return c.Media.mutate(ctx, m) case *PermissionMutation: return c.Permission.mutate(ctx, m) case *PostMutation: return c.Post.mutate(ctx, m) case *PostContentMutation: return c.PostContent.mutate(ctx, m) case *PostContributorMutation: return c.PostContributor.mutate(ctx, m) case *RoleMutation: return c.Role.mutate(ctx, m) case *UserMutation: return c.User.mutate(ctx, m) default: return nil, fmt.Errorf("ent: unknown mutation type %T", m) } } // CategoryClient is a client for the Category schema. type CategoryClient struct { config } // NewCategoryClient returns a client for the Category from the given config. func NewCategoryClient(c config) *CategoryClient { return &CategoryClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `category.Hooks(f(g(h())))`. func (c *CategoryClient) Use(hooks ...Hook) { c.hooks.Category = append(c.hooks.Category, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `category.Intercept(f(g(h())))`. func (c *CategoryClient) Intercept(interceptors ...Interceptor) { c.inters.Category = append(c.inters.Category, interceptors...) } // Create returns a builder for creating a Category entity. func (c *CategoryClient) Create() *CategoryCreate { mutation := newCategoryMutation(c.config, OpCreate) return &CategoryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Category entities. func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreateBulk { return &CategoryCreateBulk{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 *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*CategoryCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &CategoryCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Category. func (c *CategoryClient) Update() *CategoryUpdate { mutation := newCategoryMutation(c.config, OpUpdate) return &CategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *CategoryClient) UpdateOne(ca *Category) *CategoryUpdateOne { mutation := newCategoryMutation(c.config, OpUpdateOne, withCategory(ca)) return &CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *CategoryClient) UpdateOneID(id int) *CategoryUpdateOne { mutation := newCategoryMutation(c.config, OpUpdateOne, withCategoryID(id)) return &CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Category. func (c *CategoryClient) Delete() *CategoryDelete { mutation := newCategoryMutation(c.config, OpDelete) return &CategoryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *CategoryClient) DeleteOne(ca *Category) *CategoryDeleteOne { return c.DeleteOneID(ca.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *CategoryClient) DeleteOneID(id int) *CategoryDeleteOne { builder := c.Delete().Where(category.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &CategoryDeleteOne{builder} } // Query returns a query builder for Category. func (c *CategoryClient) Query() *CategoryQuery { return &CategoryQuery{ config: c.config, ctx: &QueryContext{Type: TypeCategory}, inters: c.Interceptors(), } } // Get returns a Category entity by its id. func (c *CategoryClient) Get(ctx context.Context, id int) (*Category, error) { return c.Query().Where(category.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *CategoryClient) GetX(ctx context.Context, id int) *Category { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryContents queries the contents edge of a Category. func (c *CategoryClient) QueryContents(ca *Category) *CategoryContentQuery { query := (&CategoryContentClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := ca.ID step := sqlgraph.NewStep( sqlgraph.From(category.Table, category.FieldID, id), sqlgraph.To(categorycontent.Table, categorycontent.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, category.ContentsTable, category.ContentsColumn), ) fromV = sqlgraph.Neighbors(ca.driver.Dialect(), step) return fromV, nil } return query } // QueryPosts queries the posts edge of a Category. func (c *CategoryClient) QueryPosts(ca *Category) *PostQuery { query := (&PostClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := ca.ID step := sqlgraph.NewStep( sqlgraph.From(category.Table, category.FieldID, id), sqlgraph.To(post.Table, post.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, category.PostsTable, category.PostsColumn), ) fromV = sqlgraph.Neighbors(ca.driver.Dialect(), step) return fromV, nil } return query } // QueryDailyItems queries the daily_items edge of a Category. func (c *CategoryClient) QueryDailyItems(ca *Category) *DailyQuery { query := (&DailyClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := ca.ID step := sqlgraph.NewStep( sqlgraph.From(category.Table, category.FieldID, id), sqlgraph.To(daily.Table, daily.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, category.DailyItemsTable, category.DailyItemsColumn), ) fromV = sqlgraph.Neighbors(ca.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *CategoryClient) Hooks() []Hook { return c.hooks.Category } // Interceptors returns the client interceptors. func (c *CategoryClient) Interceptors() []Interceptor { return c.inters.Category } func (c *CategoryClient) mutate(ctx context.Context, m *CategoryMutation) (Value, error) { switch m.Op() { case OpCreate: return (&CategoryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&CategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&CategoryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown Category mutation op: %q", m.Op()) } } // CategoryContentClient is a client for the CategoryContent schema. type CategoryContentClient struct { config } // NewCategoryContentClient returns a client for the CategoryContent from the given config. func NewCategoryContentClient(c config) *CategoryContentClient { return &CategoryContentClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `categorycontent.Hooks(f(g(h())))`. func (c *CategoryContentClient) Use(hooks ...Hook) { c.hooks.CategoryContent = append(c.hooks.CategoryContent, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `categorycontent.Intercept(f(g(h())))`. func (c *CategoryContentClient) Intercept(interceptors ...Interceptor) { c.inters.CategoryContent = append(c.inters.CategoryContent, interceptors...) } // Create returns a builder for creating a CategoryContent entity. func (c *CategoryContentClient) Create() *CategoryContentCreate { mutation := newCategoryContentMutation(c.config, OpCreate) return &CategoryContentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of CategoryContent entities. func (c *CategoryContentClient) CreateBulk(builders ...*CategoryContentCreate) *CategoryContentCreateBulk { return &CategoryContentCreateBulk{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 *CategoryContentClient) MapCreateBulk(slice any, setFunc func(*CategoryContentCreate, int)) *CategoryContentCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &CategoryContentCreateBulk{err: fmt.Errorf("calling to CategoryContentClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*CategoryContentCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &CategoryContentCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for CategoryContent. func (c *CategoryContentClient) Update() *CategoryContentUpdate { mutation := newCategoryContentMutation(c.config, OpUpdate) return &CategoryContentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *CategoryContentClient) UpdateOne(cc *CategoryContent) *CategoryContentUpdateOne { mutation := newCategoryContentMutation(c.config, OpUpdateOne, withCategoryContent(cc)) return &CategoryContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *CategoryContentClient) UpdateOneID(id int) *CategoryContentUpdateOne { mutation := newCategoryContentMutation(c.config, OpUpdateOne, withCategoryContentID(id)) return &CategoryContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for CategoryContent. func (c *CategoryContentClient) Delete() *CategoryContentDelete { mutation := newCategoryContentMutation(c.config, OpDelete) return &CategoryContentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *CategoryContentClient) DeleteOne(cc *CategoryContent) *CategoryContentDeleteOne { return c.DeleteOneID(cc.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *CategoryContentClient) DeleteOneID(id int) *CategoryContentDeleteOne { builder := c.Delete().Where(categorycontent.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &CategoryContentDeleteOne{builder} } // Query returns a query builder for CategoryContent. func (c *CategoryContentClient) Query() *CategoryContentQuery { return &CategoryContentQuery{ config: c.config, ctx: &QueryContext{Type: TypeCategoryContent}, inters: c.Interceptors(), } } // Get returns a CategoryContent entity by its id. func (c *CategoryContentClient) Get(ctx context.Context, id int) (*CategoryContent, error) { return c.Query().Where(categorycontent.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *CategoryContentClient) GetX(ctx context.Context, id int) *CategoryContent { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryCategory queries the category edge of a CategoryContent. func (c *CategoryContentClient) QueryCategory(cc *CategoryContent) *CategoryQuery { query := (&CategoryClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := cc.ID step := sqlgraph.NewStep( sqlgraph.From(categorycontent.Table, categorycontent.FieldID, id), sqlgraph.To(category.Table, category.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, categorycontent.CategoryTable, categorycontent.CategoryColumn), ) fromV = sqlgraph.Neighbors(cc.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *CategoryContentClient) Hooks() []Hook { return c.hooks.CategoryContent } // Interceptors returns the client interceptors. func (c *CategoryContentClient) Interceptors() []Interceptor { return c.inters.CategoryContent } func (c *CategoryContentClient) mutate(ctx context.Context, m *CategoryContentMutation) (Value, error) { switch m.Op() { case OpCreate: return (&CategoryContentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&CategoryContentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&CategoryContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&CategoryContentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown CategoryContent mutation op: %q", m.Op()) } } // ContributorClient is a client for the Contributor schema. type ContributorClient struct { config } // NewContributorClient returns a client for the Contributor from the given config. func NewContributorClient(c config) *ContributorClient { return &ContributorClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `contributor.Hooks(f(g(h())))`. func (c *ContributorClient) Use(hooks ...Hook) { c.hooks.Contributor = append(c.hooks.Contributor, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `contributor.Intercept(f(g(h())))`. func (c *ContributorClient) Intercept(interceptors ...Interceptor) { c.inters.Contributor = append(c.inters.Contributor, interceptors...) } // Create returns a builder for creating a Contributor entity. func (c *ContributorClient) Create() *ContributorCreate { mutation := newContributorMutation(c.config, OpCreate) return &ContributorCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Contributor entities. func (c *ContributorClient) CreateBulk(builders ...*ContributorCreate) *ContributorCreateBulk { return &ContributorCreateBulk{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 *ContributorClient) MapCreateBulk(slice any, setFunc func(*ContributorCreate, int)) *ContributorCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &ContributorCreateBulk{err: fmt.Errorf("calling to ContributorClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*ContributorCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &ContributorCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Contributor. func (c *ContributorClient) Update() *ContributorUpdate { mutation := newContributorMutation(c.config, OpUpdate) return &ContributorUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *ContributorClient) UpdateOne(co *Contributor) *ContributorUpdateOne { mutation := newContributorMutation(c.config, OpUpdateOne, withContributor(co)) return &ContributorUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *ContributorClient) UpdateOneID(id int) *ContributorUpdateOne { mutation := newContributorMutation(c.config, OpUpdateOne, withContributorID(id)) return &ContributorUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Contributor. func (c *ContributorClient) Delete() *ContributorDelete { mutation := newContributorMutation(c.config, OpDelete) return &ContributorDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *ContributorClient) DeleteOne(co *Contributor) *ContributorDeleteOne { return c.DeleteOneID(co.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *ContributorClient) DeleteOneID(id int) *ContributorDeleteOne { builder := c.Delete().Where(contributor.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &ContributorDeleteOne{builder} } // Query returns a query builder for Contributor. func (c *ContributorClient) Query() *ContributorQuery { return &ContributorQuery{ config: c.config, ctx: &QueryContext{Type: TypeContributor}, inters: c.Interceptors(), } } // Get returns a Contributor entity by its id. func (c *ContributorClient) Get(ctx context.Context, id int) (*Contributor, error) { return c.Query().Where(contributor.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *ContributorClient) GetX(ctx context.Context, id int) *Contributor { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryUser queries the user edge of a Contributor. func (c *ContributorClient) QueryUser(co *Contributor) *UserQuery { query := (&UserClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := co.ID step := sqlgraph.NewStep( sqlgraph.From(contributor.Table, contributor.FieldID, id), sqlgraph.To(user.Table, user.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, contributor.UserTable, contributor.UserColumn), ) fromV = sqlgraph.Neighbors(co.driver.Dialect(), step) return fromV, nil } return query } // QuerySocialLinks queries the social_links edge of a Contributor. func (c *ContributorClient) QuerySocialLinks(co *Contributor) *ContributorSocialLinkQuery { query := (&ContributorSocialLinkClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := co.ID step := sqlgraph.NewStep( sqlgraph.From(contributor.Table, contributor.FieldID, id), sqlgraph.To(contributorsociallink.Table, contributorsociallink.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, contributor.SocialLinksTable, contributor.SocialLinksColumn), ) fromV = sqlgraph.Neighbors(co.driver.Dialect(), step) return fromV, nil } return query } // QueryPosts queries the posts edge of a Contributor. func (c *ContributorClient) QueryPosts(co *Contributor) *PostContributorQuery { query := (&PostContributorClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := co.ID step := sqlgraph.NewStep( sqlgraph.From(contributor.Table, contributor.FieldID, id), sqlgraph.To(postcontributor.Table, postcontributor.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, contributor.PostsTable, contributor.PostsColumn), ) fromV = sqlgraph.Neighbors(co.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *ContributorClient) Hooks() []Hook { return c.hooks.Contributor } // Interceptors returns the client interceptors. func (c *ContributorClient) Interceptors() []Interceptor { return c.inters.Contributor } func (c *ContributorClient) mutate(ctx context.Context, m *ContributorMutation) (Value, error) { switch m.Op() { case OpCreate: return (&ContributorCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&ContributorUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&ContributorUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&ContributorDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown Contributor mutation op: %q", m.Op()) } } // ContributorRoleClient is a client for the ContributorRole schema. type ContributorRoleClient struct { config } // NewContributorRoleClient returns a client for the ContributorRole from the given config. func NewContributorRoleClient(c config) *ContributorRoleClient { return &ContributorRoleClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `contributorrole.Hooks(f(g(h())))`. func (c *ContributorRoleClient) Use(hooks ...Hook) { c.hooks.ContributorRole = append(c.hooks.ContributorRole, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `contributorrole.Intercept(f(g(h())))`. func (c *ContributorRoleClient) Intercept(interceptors ...Interceptor) { c.inters.ContributorRole = append(c.inters.ContributorRole, interceptors...) } // Create returns a builder for creating a ContributorRole entity. func (c *ContributorRoleClient) Create() *ContributorRoleCreate { mutation := newContributorRoleMutation(c.config, OpCreate) return &ContributorRoleCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of ContributorRole entities. func (c *ContributorRoleClient) CreateBulk(builders ...*ContributorRoleCreate) *ContributorRoleCreateBulk { return &ContributorRoleCreateBulk{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 *ContributorRoleClient) MapCreateBulk(slice any, setFunc func(*ContributorRoleCreate, int)) *ContributorRoleCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &ContributorRoleCreateBulk{err: fmt.Errorf("calling to ContributorRoleClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*ContributorRoleCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &ContributorRoleCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for ContributorRole. func (c *ContributorRoleClient) Update() *ContributorRoleUpdate { mutation := newContributorRoleMutation(c.config, OpUpdate) return &ContributorRoleUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *ContributorRoleClient) UpdateOne(cr *ContributorRole) *ContributorRoleUpdateOne { mutation := newContributorRoleMutation(c.config, OpUpdateOne, withContributorRole(cr)) return &ContributorRoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *ContributorRoleClient) UpdateOneID(id int) *ContributorRoleUpdateOne { mutation := newContributorRoleMutation(c.config, OpUpdateOne, withContributorRoleID(id)) return &ContributorRoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for ContributorRole. func (c *ContributorRoleClient) Delete() *ContributorRoleDelete { mutation := newContributorRoleMutation(c.config, OpDelete) return &ContributorRoleDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *ContributorRoleClient) DeleteOne(cr *ContributorRole) *ContributorRoleDeleteOne { return c.DeleteOneID(cr.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *ContributorRoleClient) DeleteOneID(id int) *ContributorRoleDeleteOne { builder := c.Delete().Where(contributorrole.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &ContributorRoleDeleteOne{builder} } // Query returns a query builder for ContributorRole. func (c *ContributorRoleClient) Query() *ContributorRoleQuery { return &ContributorRoleQuery{ config: c.config, ctx: &QueryContext{Type: TypeContributorRole}, inters: c.Interceptors(), } } // Get returns a ContributorRole entity by its id. func (c *ContributorRoleClient) Get(ctx context.Context, id int) (*ContributorRole, error) { return c.Query().Where(contributorrole.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *ContributorRoleClient) GetX(ctx context.Context, id int) *ContributorRole { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryPostContributors queries the post_contributors edge of a ContributorRole. func (c *ContributorRoleClient) QueryPostContributors(cr *ContributorRole) *PostContributorQuery { query := (&PostContributorClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := cr.ID step := sqlgraph.NewStep( sqlgraph.From(contributorrole.Table, contributorrole.FieldID, id), sqlgraph.To(postcontributor.Table, postcontributor.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, contributorrole.PostContributorsTable, contributorrole.PostContributorsColumn), ) fromV = sqlgraph.Neighbors(cr.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *ContributorRoleClient) Hooks() []Hook { return c.hooks.ContributorRole } // Interceptors returns the client interceptors. func (c *ContributorRoleClient) Interceptors() []Interceptor { return c.inters.ContributorRole } func (c *ContributorRoleClient) mutate(ctx context.Context, m *ContributorRoleMutation) (Value, error) { switch m.Op() { case OpCreate: return (&ContributorRoleCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&ContributorRoleUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&ContributorRoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&ContributorRoleDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown ContributorRole mutation op: %q", m.Op()) } } // ContributorSocialLinkClient is a client for the ContributorSocialLink schema. type ContributorSocialLinkClient struct { config } // NewContributorSocialLinkClient returns a client for the ContributorSocialLink from the given config. func NewContributorSocialLinkClient(c config) *ContributorSocialLinkClient { return &ContributorSocialLinkClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `contributorsociallink.Hooks(f(g(h())))`. func (c *ContributorSocialLinkClient) Use(hooks ...Hook) { c.hooks.ContributorSocialLink = append(c.hooks.ContributorSocialLink, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `contributorsociallink.Intercept(f(g(h())))`. func (c *ContributorSocialLinkClient) Intercept(interceptors ...Interceptor) { c.inters.ContributorSocialLink = append(c.inters.ContributorSocialLink, interceptors...) } // Create returns a builder for creating a ContributorSocialLink entity. func (c *ContributorSocialLinkClient) Create() *ContributorSocialLinkCreate { mutation := newContributorSocialLinkMutation(c.config, OpCreate) return &ContributorSocialLinkCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of ContributorSocialLink entities. func (c *ContributorSocialLinkClient) CreateBulk(builders ...*ContributorSocialLinkCreate) *ContributorSocialLinkCreateBulk { return &ContributorSocialLinkCreateBulk{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 *ContributorSocialLinkClient) MapCreateBulk(slice any, setFunc func(*ContributorSocialLinkCreate, int)) *ContributorSocialLinkCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &ContributorSocialLinkCreateBulk{err: fmt.Errorf("calling to ContributorSocialLinkClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*ContributorSocialLinkCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &ContributorSocialLinkCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for ContributorSocialLink. func (c *ContributorSocialLinkClient) Update() *ContributorSocialLinkUpdate { mutation := newContributorSocialLinkMutation(c.config, OpUpdate) return &ContributorSocialLinkUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *ContributorSocialLinkClient) UpdateOne(csl *ContributorSocialLink) *ContributorSocialLinkUpdateOne { mutation := newContributorSocialLinkMutation(c.config, OpUpdateOne, withContributorSocialLink(csl)) return &ContributorSocialLinkUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *ContributorSocialLinkClient) UpdateOneID(id int) *ContributorSocialLinkUpdateOne { mutation := newContributorSocialLinkMutation(c.config, OpUpdateOne, withContributorSocialLinkID(id)) return &ContributorSocialLinkUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for ContributorSocialLink. func (c *ContributorSocialLinkClient) Delete() *ContributorSocialLinkDelete { mutation := newContributorSocialLinkMutation(c.config, OpDelete) return &ContributorSocialLinkDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *ContributorSocialLinkClient) DeleteOne(csl *ContributorSocialLink) *ContributorSocialLinkDeleteOne { return c.DeleteOneID(csl.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *ContributorSocialLinkClient) DeleteOneID(id int) *ContributorSocialLinkDeleteOne { builder := c.Delete().Where(contributorsociallink.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &ContributorSocialLinkDeleteOne{builder} } // Query returns a query builder for ContributorSocialLink. func (c *ContributorSocialLinkClient) Query() *ContributorSocialLinkQuery { return &ContributorSocialLinkQuery{ config: c.config, ctx: &QueryContext{Type: TypeContributorSocialLink}, inters: c.Interceptors(), } } // Get returns a ContributorSocialLink entity by its id. func (c *ContributorSocialLinkClient) Get(ctx context.Context, id int) (*ContributorSocialLink, error) { return c.Query().Where(contributorsociallink.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *ContributorSocialLinkClient) GetX(ctx context.Context, id int) *ContributorSocialLink { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryContributor queries the contributor edge of a ContributorSocialLink. func (c *ContributorSocialLinkClient) QueryContributor(csl *ContributorSocialLink) *ContributorQuery { query := (&ContributorClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := csl.ID step := sqlgraph.NewStep( sqlgraph.From(contributorsociallink.Table, contributorsociallink.FieldID, id), sqlgraph.To(contributor.Table, contributor.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, contributorsociallink.ContributorTable, contributorsociallink.ContributorColumn), ) fromV = sqlgraph.Neighbors(csl.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *ContributorSocialLinkClient) Hooks() []Hook { return c.hooks.ContributorSocialLink } // Interceptors returns the client interceptors. func (c *ContributorSocialLinkClient) Interceptors() []Interceptor { return c.inters.ContributorSocialLink } func (c *ContributorSocialLinkClient) mutate(ctx context.Context, m *ContributorSocialLinkMutation) (Value, error) { switch m.Op() { case OpCreate: return (&ContributorSocialLinkCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&ContributorSocialLinkUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&ContributorSocialLinkUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&ContributorSocialLinkDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown ContributorSocialLink mutation op: %q", m.Op()) } } // DailyClient is a client for the Daily schema. type DailyClient struct { config } // NewDailyClient returns a client for the Daily from the given config. func NewDailyClient(c config) *DailyClient { return &DailyClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `daily.Hooks(f(g(h())))`. func (c *DailyClient) Use(hooks ...Hook) { c.hooks.Daily = append(c.hooks.Daily, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `daily.Intercept(f(g(h())))`. func (c *DailyClient) Intercept(interceptors ...Interceptor) { c.inters.Daily = append(c.inters.Daily, interceptors...) } // Create returns a builder for creating a Daily entity. func (c *DailyClient) Create() *DailyCreate { mutation := newDailyMutation(c.config, OpCreate) return &DailyCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Daily entities. func (c *DailyClient) CreateBulk(builders ...*DailyCreate) *DailyCreateBulk { return &DailyCreateBulk{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 *DailyClient) MapCreateBulk(slice any, setFunc func(*DailyCreate, int)) *DailyCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &DailyCreateBulk{err: fmt.Errorf("calling to DailyClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*DailyCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &DailyCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Daily. func (c *DailyClient) Update() *DailyUpdate { mutation := newDailyMutation(c.config, OpUpdate) return &DailyUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *DailyClient) UpdateOne(d *Daily) *DailyUpdateOne { mutation := newDailyMutation(c.config, OpUpdateOne, withDaily(d)) return &DailyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *DailyClient) UpdateOneID(id string) *DailyUpdateOne { mutation := newDailyMutation(c.config, OpUpdateOne, withDailyID(id)) return &DailyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Daily. func (c *DailyClient) Delete() *DailyDelete { mutation := newDailyMutation(c.config, OpDelete) return &DailyDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *DailyClient) DeleteOne(d *Daily) *DailyDeleteOne { return c.DeleteOneID(d.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *DailyClient) DeleteOneID(id string) *DailyDeleteOne { builder := c.Delete().Where(daily.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &DailyDeleteOne{builder} } // Query returns a query builder for Daily. func (c *DailyClient) Query() *DailyQuery { return &DailyQuery{ config: c.config, ctx: &QueryContext{Type: TypeDaily}, inters: c.Interceptors(), } } // Get returns a Daily entity by its id. func (c *DailyClient) Get(ctx context.Context, id string) (*Daily, error) { return c.Query().Where(daily.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *DailyClient) GetX(ctx context.Context, id string) *Daily { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryCategory queries the category edge of a Daily. func (c *DailyClient) QueryCategory(d *Daily) *CategoryQuery { query := (&CategoryClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := d.ID step := sqlgraph.NewStep( sqlgraph.From(daily.Table, daily.FieldID, id), sqlgraph.To(category.Table, category.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, daily.CategoryTable, daily.CategoryColumn), ) fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) return fromV, nil } return query } // QueryContents queries the contents edge of a Daily. func (c *DailyClient) QueryContents(d *Daily) *DailyContentQuery { query := (&DailyContentClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := d.ID step := sqlgraph.NewStep( sqlgraph.From(daily.Table, daily.FieldID, id), sqlgraph.To(dailycontent.Table, dailycontent.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, daily.ContentsTable, daily.ContentsColumn), ) fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *DailyClient) Hooks() []Hook { return c.hooks.Daily } // Interceptors returns the client interceptors. func (c *DailyClient) Interceptors() []Interceptor { return c.inters.Daily } func (c *DailyClient) mutate(ctx context.Context, m *DailyMutation) (Value, error) { switch m.Op() { case OpCreate: return (&DailyCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&DailyUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&DailyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&DailyDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown Daily mutation op: %q", m.Op()) } } // DailyCategoryClient is a client for the DailyCategory schema. type DailyCategoryClient struct { config } // NewDailyCategoryClient returns a client for the DailyCategory from the given config. func NewDailyCategoryClient(c config) *DailyCategoryClient { return &DailyCategoryClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `dailycategory.Hooks(f(g(h())))`. func (c *DailyCategoryClient) Use(hooks ...Hook) { c.hooks.DailyCategory = append(c.hooks.DailyCategory, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `dailycategory.Intercept(f(g(h())))`. func (c *DailyCategoryClient) Intercept(interceptors ...Interceptor) { c.inters.DailyCategory = append(c.inters.DailyCategory, interceptors...) } // Create returns a builder for creating a DailyCategory entity. func (c *DailyCategoryClient) Create() *DailyCategoryCreate { mutation := newDailyCategoryMutation(c.config, OpCreate) return &DailyCategoryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of DailyCategory entities. func (c *DailyCategoryClient) CreateBulk(builders ...*DailyCategoryCreate) *DailyCategoryCreateBulk { return &DailyCategoryCreateBulk{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 *DailyCategoryClient) MapCreateBulk(slice any, setFunc func(*DailyCategoryCreate, int)) *DailyCategoryCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &DailyCategoryCreateBulk{err: fmt.Errorf("calling to DailyCategoryClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*DailyCategoryCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &DailyCategoryCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for DailyCategory. func (c *DailyCategoryClient) Update() *DailyCategoryUpdate { mutation := newDailyCategoryMutation(c.config, OpUpdate) return &DailyCategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *DailyCategoryClient) UpdateOne(dc *DailyCategory) *DailyCategoryUpdateOne { mutation := newDailyCategoryMutation(c.config, OpUpdateOne, withDailyCategory(dc)) return &DailyCategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *DailyCategoryClient) UpdateOneID(id int) *DailyCategoryUpdateOne { mutation := newDailyCategoryMutation(c.config, OpUpdateOne, withDailyCategoryID(id)) return &DailyCategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for DailyCategory. func (c *DailyCategoryClient) Delete() *DailyCategoryDelete { mutation := newDailyCategoryMutation(c.config, OpDelete) return &DailyCategoryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *DailyCategoryClient) DeleteOne(dc *DailyCategory) *DailyCategoryDeleteOne { return c.DeleteOneID(dc.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *DailyCategoryClient) DeleteOneID(id int) *DailyCategoryDeleteOne { builder := c.Delete().Where(dailycategory.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &DailyCategoryDeleteOne{builder} } // Query returns a query builder for DailyCategory. func (c *DailyCategoryClient) Query() *DailyCategoryQuery { return &DailyCategoryQuery{ config: c.config, ctx: &QueryContext{Type: TypeDailyCategory}, inters: c.Interceptors(), } } // Get returns a DailyCategory entity by its id. func (c *DailyCategoryClient) Get(ctx context.Context, id int) (*DailyCategory, error) { return c.Query().Where(dailycategory.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *DailyCategoryClient) GetX(ctx context.Context, id int) *DailyCategory { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryContents queries the contents edge of a DailyCategory. func (c *DailyCategoryClient) QueryContents(dc *DailyCategory) *DailyCategoryContentQuery { query := (&DailyCategoryContentClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := dc.ID step := sqlgraph.NewStep( sqlgraph.From(dailycategory.Table, dailycategory.FieldID, id), sqlgraph.To(dailycategorycontent.Table, dailycategorycontent.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, dailycategory.ContentsTable, dailycategory.ContentsColumn), ) fromV = sqlgraph.Neighbors(dc.driver.Dialect(), step) return fromV, nil } return query } // QueryDailyItems queries the daily_items edge of a DailyCategory. func (c *DailyCategoryClient) QueryDailyItems(dc *DailyCategory) *DailyQuery { query := (&DailyClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := dc.ID step := sqlgraph.NewStep( sqlgraph.From(dailycategory.Table, dailycategory.FieldID, id), sqlgraph.To(daily.Table, daily.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, dailycategory.DailyItemsTable, dailycategory.DailyItemsColumn), ) fromV = sqlgraph.Neighbors(dc.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *DailyCategoryClient) Hooks() []Hook { return c.hooks.DailyCategory } // Interceptors returns the client interceptors. func (c *DailyCategoryClient) Interceptors() []Interceptor { return c.inters.DailyCategory } func (c *DailyCategoryClient) mutate(ctx context.Context, m *DailyCategoryMutation) (Value, error) { switch m.Op() { case OpCreate: return (&DailyCategoryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&DailyCategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&DailyCategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&DailyCategoryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown DailyCategory mutation op: %q", m.Op()) } } // DailyCategoryContentClient is a client for the DailyCategoryContent schema. type DailyCategoryContentClient struct { config } // NewDailyCategoryContentClient returns a client for the DailyCategoryContent from the given config. func NewDailyCategoryContentClient(c config) *DailyCategoryContentClient { return &DailyCategoryContentClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `dailycategorycontent.Hooks(f(g(h())))`. func (c *DailyCategoryContentClient) Use(hooks ...Hook) { c.hooks.DailyCategoryContent = append(c.hooks.DailyCategoryContent, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `dailycategorycontent.Intercept(f(g(h())))`. func (c *DailyCategoryContentClient) Intercept(interceptors ...Interceptor) { c.inters.DailyCategoryContent = append(c.inters.DailyCategoryContent, interceptors...) } // Create returns a builder for creating a DailyCategoryContent entity. func (c *DailyCategoryContentClient) Create() *DailyCategoryContentCreate { mutation := newDailyCategoryContentMutation(c.config, OpCreate) return &DailyCategoryContentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of DailyCategoryContent entities. func (c *DailyCategoryContentClient) CreateBulk(builders ...*DailyCategoryContentCreate) *DailyCategoryContentCreateBulk { return &DailyCategoryContentCreateBulk{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 *DailyCategoryContentClient) MapCreateBulk(slice any, setFunc func(*DailyCategoryContentCreate, int)) *DailyCategoryContentCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &DailyCategoryContentCreateBulk{err: fmt.Errorf("calling to DailyCategoryContentClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*DailyCategoryContentCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &DailyCategoryContentCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for DailyCategoryContent. func (c *DailyCategoryContentClient) Update() *DailyCategoryContentUpdate { mutation := newDailyCategoryContentMutation(c.config, OpUpdate) return &DailyCategoryContentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *DailyCategoryContentClient) UpdateOne(dcc *DailyCategoryContent) *DailyCategoryContentUpdateOne { mutation := newDailyCategoryContentMutation(c.config, OpUpdateOne, withDailyCategoryContent(dcc)) return &DailyCategoryContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *DailyCategoryContentClient) UpdateOneID(id int) *DailyCategoryContentUpdateOne { mutation := newDailyCategoryContentMutation(c.config, OpUpdateOne, withDailyCategoryContentID(id)) return &DailyCategoryContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for DailyCategoryContent. func (c *DailyCategoryContentClient) Delete() *DailyCategoryContentDelete { mutation := newDailyCategoryContentMutation(c.config, OpDelete) return &DailyCategoryContentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *DailyCategoryContentClient) DeleteOne(dcc *DailyCategoryContent) *DailyCategoryContentDeleteOne { return c.DeleteOneID(dcc.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *DailyCategoryContentClient) DeleteOneID(id int) *DailyCategoryContentDeleteOne { builder := c.Delete().Where(dailycategorycontent.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &DailyCategoryContentDeleteOne{builder} } // Query returns a query builder for DailyCategoryContent. func (c *DailyCategoryContentClient) Query() *DailyCategoryContentQuery { return &DailyCategoryContentQuery{ config: c.config, ctx: &QueryContext{Type: TypeDailyCategoryContent}, inters: c.Interceptors(), } } // Get returns a DailyCategoryContent entity by its id. func (c *DailyCategoryContentClient) Get(ctx context.Context, id int) (*DailyCategoryContent, error) { return c.Query().Where(dailycategorycontent.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *DailyCategoryContentClient) GetX(ctx context.Context, id int) *DailyCategoryContent { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryCategory queries the category edge of a DailyCategoryContent. func (c *DailyCategoryContentClient) QueryCategory(dcc *DailyCategoryContent) *DailyCategoryQuery { query := (&DailyCategoryClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := dcc.ID step := sqlgraph.NewStep( sqlgraph.From(dailycategorycontent.Table, dailycategorycontent.FieldID, id), sqlgraph.To(dailycategory.Table, dailycategory.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, dailycategorycontent.CategoryTable, dailycategorycontent.CategoryColumn), ) fromV = sqlgraph.Neighbors(dcc.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *DailyCategoryContentClient) Hooks() []Hook { return c.hooks.DailyCategoryContent } // Interceptors returns the client interceptors. func (c *DailyCategoryContentClient) Interceptors() []Interceptor { return c.inters.DailyCategoryContent } func (c *DailyCategoryContentClient) mutate(ctx context.Context, m *DailyCategoryContentMutation) (Value, error) { switch m.Op() { case OpCreate: return (&DailyCategoryContentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&DailyCategoryContentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&DailyCategoryContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&DailyCategoryContentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown DailyCategoryContent mutation op: %q", m.Op()) } } // DailyContentClient is a client for the DailyContent schema. type DailyContentClient struct { config } // NewDailyContentClient returns a client for the DailyContent from the given config. func NewDailyContentClient(c config) *DailyContentClient { return &DailyContentClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `dailycontent.Hooks(f(g(h())))`. func (c *DailyContentClient) Use(hooks ...Hook) { c.hooks.DailyContent = append(c.hooks.DailyContent, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `dailycontent.Intercept(f(g(h())))`. func (c *DailyContentClient) Intercept(interceptors ...Interceptor) { c.inters.DailyContent = append(c.inters.DailyContent, interceptors...) } // Create returns a builder for creating a DailyContent entity. func (c *DailyContentClient) Create() *DailyContentCreate { mutation := newDailyContentMutation(c.config, OpCreate) return &DailyContentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of DailyContent entities. func (c *DailyContentClient) CreateBulk(builders ...*DailyContentCreate) *DailyContentCreateBulk { return &DailyContentCreateBulk{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 *DailyContentClient) MapCreateBulk(slice any, setFunc func(*DailyContentCreate, int)) *DailyContentCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &DailyContentCreateBulk{err: fmt.Errorf("calling to DailyContentClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*DailyContentCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &DailyContentCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for DailyContent. func (c *DailyContentClient) Update() *DailyContentUpdate { mutation := newDailyContentMutation(c.config, OpUpdate) return &DailyContentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *DailyContentClient) UpdateOne(dc *DailyContent) *DailyContentUpdateOne { mutation := newDailyContentMutation(c.config, OpUpdateOne, withDailyContent(dc)) return &DailyContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *DailyContentClient) UpdateOneID(id int) *DailyContentUpdateOne { mutation := newDailyContentMutation(c.config, OpUpdateOne, withDailyContentID(id)) return &DailyContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for DailyContent. func (c *DailyContentClient) Delete() *DailyContentDelete { mutation := newDailyContentMutation(c.config, OpDelete) return &DailyContentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *DailyContentClient) DeleteOne(dc *DailyContent) *DailyContentDeleteOne { return c.DeleteOneID(dc.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *DailyContentClient) DeleteOneID(id int) *DailyContentDeleteOne { builder := c.Delete().Where(dailycontent.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &DailyContentDeleteOne{builder} } // Query returns a query builder for DailyContent. func (c *DailyContentClient) Query() *DailyContentQuery { return &DailyContentQuery{ config: c.config, ctx: &QueryContext{Type: TypeDailyContent}, inters: c.Interceptors(), } } // Get returns a DailyContent entity by its id. func (c *DailyContentClient) Get(ctx context.Context, id int) (*DailyContent, error) { return c.Query().Where(dailycontent.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *DailyContentClient) GetX(ctx context.Context, id int) *DailyContent { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryDaily queries the daily edge of a DailyContent. func (c *DailyContentClient) QueryDaily(dc *DailyContent) *DailyQuery { query := (&DailyClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := dc.ID step := sqlgraph.NewStep( sqlgraph.From(dailycontent.Table, dailycontent.FieldID, id), sqlgraph.To(daily.Table, daily.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, dailycontent.DailyTable, dailycontent.DailyColumn), ) fromV = sqlgraph.Neighbors(dc.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *DailyContentClient) Hooks() []Hook { return c.hooks.DailyContent } // Interceptors returns the client interceptors. func (c *DailyContentClient) Interceptors() []Interceptor { return c.inters.DailyContent } func (c *DailyContentClient) mutate(ctx context.Context, m *DailyContentMutation) (Value, error) { switch m.Op() { case OpCreate: return (&DailyContentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&DailyContentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&DailyContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&DailyContentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown DailyContent mutation op: %q", m.Op()) } } // MediaClient is a client for the Media schema. type MediaClient struct { config } // NewMediaClient returns a client for the Media from the given config. func NewMediaClient(c config) *MediaClient { return &MediaClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `media.Hooks(f(g(h())))`. func (c *MediaClient) Use(hooks ...Hook) { c.hooks.Media = append(c.hooks.Media, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `media.Intercept(f(g(h())))`. func (c *MediaClient) Intercept(interceptors ...Interceptor) { c.inters.Media = append(c.inters.Media, interceptors...) } // Create returns a builder for creating a Media entity. func (c *MediaClient) Create() *MediaCreate { mutation := newMediaMutation(c.config, OpCreate) return &MediaCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Media entities. func (c *MediaClient) CreateBulk(builders ...*MediaCreate) *MediaCreateBulk { return &MediaCreateBulk{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 *MediaClient) MapCreateBulk(slice any, setFunc func(*MediaCreate, int)) *MediaCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &MediaCreateBulk{err: fmt.Errorf("calling to MediaClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*MediaCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &MediaCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Media. func (c *MediaClient) Update() *MediaUpdate { mutation := newMediaMutation(c.config, OpUpdate) return &MediaUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *MediaClient) UpdateOne(m *Media) *MediaUpdateOne { mutation := newMediaMutation(c.config, OpUpdateOne, withMedia(m)) return &MediaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *MediaClient) UpdateOneID(id int) *MediaUpdateOne { mutation := newMediaMutation(c.config, OpUpdateOne, withMediaID(id)) return &MediaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Media. func (c *MediaClient) Delete() *MediaDelete { mutation := newMediaMutation(c.config, OpDelete) return &MediaDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *MediaClient) DeleteOne(m *Media) *MediaDeleteOne { return c.DeleteOneID(m.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *MediaClient) DeleteOneID(id int) *MediaDeleteOne { builder := c.Delete().Where(media.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &MediaDeleteOne{builder} } // Query returns a query builder for Media. func (c *MediaClient) Query() *MediaQuery { return &MediaQuery{ config: c.config, ctx: &QueryContext{Type: TypeMedia}, inters: c.Interceptors(), } } // Get returns a Media entity by its id. func (c *MediaClient) Get(ctx context.Context, id int) (*Media, error) { return c.Query().Where(media.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *MediaClient) GetX(ctx context.Context, id int) *Media { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryOwner queries the owner edge of a Media. func (c *MediaClient) QueryOwner(m *Media) *UserQuery { query := (&UserClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := m.ID step := sqlgraph.NewStep( sqlgraph.From(media.Table, media.FieldID, id), sqlgraph.To(user.Table, user.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, media.OwnerTable, media.OwnerColumn), ) fromV = sqlgraph.Neighbors(m.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *MediaClient) Hooks() []Hook { return c.hooks.Media } // Interceptors returns the client interceptors. func (c *MediaClient) Interceptors() []Interceptor { return c.inters.Media } func (c *MediaClient) mutate(ctx context.Context, m *MediaMutation) (Value, error) { switch m.Op() { case OpCreate: return (&MediaCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&MediaUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&MediaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&MediaDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown Media mutation op: %q", m.Op()) } } // PermissionClient is a client for the Permission schema. type PermissionClient struct { config } // NewPermissionClient returns a client for the Permission from the given config. func NewPermissionClient(c config) *PermissionClient { return &PermissionClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `permission.Hooks(f(g(h())))`. func (c *PermissionClient) Use(hooks ...Hook) { c.hooks.Permission = append(c.hooks.Permission, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `permission.Intercept(f(g(h())))`. func (c *PermissionClient) Intercept(interceptors ...Interceptor) { c.inters.Permission = append(c.inters.Permission, interceptors...) } // Create returns a builder for creating a Permission entity. func (c *PermissionClient) Create() *PermissionCreate { mutation := newPermissionMutation(c.config, OpCreate) return &PermissionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Permission entities. func (c *PermissionClient) CreateBulk(builders ...*PermissionCreate) *PermissionCreateBulk { return &PermissionCreateBulk{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 *PermissionClient) MapCreateBulk(slice any, setFunc func(*PermissionCreate, int)) *PermissionCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &PermissionCreateBulk{err: fmt.Errorf("calling to PermissionClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*PermissionCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &PermissionCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Permission. func (c *PermissionClient) Update() *PermissionUpdate { mutation := newPermissionMutation(c.config, OpUpdate) return &PermissionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *PermissionClient) UpdateOne(pe *Permission) *PermissionUpdateOne { mutation := newPermissionMutation(c.config, OpUpdateOne, withPermission(pe)) return &PermissionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *PermissionClient) UpdateOneID(id int) *PermissionUpdateOne { mutation := newPermissionMutation(c.config, OpUpdateOne, withPermissionID(id)) return &PermissionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Permission. func (c *PermissionClient) Delete() *PermissionDelete { mutation := newPermissionMutation(c.config, OpDelete) return &PermissionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *PermissionClient) DeleteOne(pe *Permission) *PermissionDeleteOne { return c.DeleteOneID(pe.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *PermissionClient) DeleteOneID(id int) *PermissionDeleteOne { builder := c.Delete().Where(permission.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &PermissionDeleteOne{builder} } // Query returns a query builder for Permission. func (c *PermissionClient) Query() *PermissionQuery { return &PermissionQuery{ config: c.config, ctx: &QueryContext{Type: TypePermission}, inters: c.Interceptors(), } } // Get returns a Permission entity by its id. func (c *PermissionClient) Get(ctx context.Context, id int) (*Permission, error) { return c.Query().Where(permission.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *PermissionClient) GetX(ctx context.Context, id int) *Permission { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryRoles queries the roles edge of a Permission. func (c *PermissionClient) QueryRoles(pe *Permission) *RoleQuery { query := (&RoleClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := pe.ID step := sqlgraph.NewStep( sqlgraph.From(permission.Table, permission.FieldID, id), sqlgraph.To(role.Table, role.FieldID), sqlgraph.Edge(sqlgraph.M2M, true, permission.RolesTable, permission.RolesPrimaryKey...), ) fromV = sqlgraph.Neighbors(pe.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *PermissionClient) Hooks() []Hook { return c.hooks.Permission } // Interceptors returns the client interceptors. func (c *PermissionClient) Interceptors() []Interceptor { return c.inters.Permission } func (c *PermissionClient) mutate(ctx context.Context, m *PermissionMutation) (Value, error) { switch m.Op() { case OpCreate: return (&PermissionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&PermissionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&PermissionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&PermissionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown Permission mutation op: %q", m.Op()) } } // PostClient is a client for the Post schema. type PostClient struct { config } // NewPostClient returns a client for the Post from the given config. func NewPostClient(c config) *PostClient { return &PostClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `post.Hooks(f(g(h())))`. func (c *PostClient) Use(hooks ...Hook) { c.hooks.Post = append(c.hooks.Post, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `post.Intercept(f(g(h())))`. func (c *PostClient) Intercept(interceptors ...Interceptor) { c.inters.Post = append(c.inters.Post, interceptors...) } // Create returns a builder for creating a Post entity. func (c *PostClient) Create() *PostCreate { mutation := newPostMutation(c.config, OpCreate) return &PostCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Post entities. func (c *PostClient) CreateBulk(builders ...*PostCreate) *PostCreateBulk { return &PostCreateBulk{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 *PostClient) MapCreateBulk(slice any, setFunc func(*PostCreate, int)) *PostCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &PostCreateBulk{err: fmt.Errorf("calling to PostClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*PostCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &PostCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Post. func (c *PostClient) Update() *PostUpdate { mutation := newPostMutation(c.config, OpUpdate) return &PostUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *PostClient) UpdateOne(po *Post) *PostUpdateOne { mutation := newPostMutation(c.config, OpUpdateOne, withPost(po)) return &PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *PostClient) UpdateOneID(id int) *PostUpdateOne { mutation := newPostMutation(c.config, OpUpdateOne, withPostID(id)) return &PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Post. func (c *PostClient) Delete() *PostDelete { mutation := newPostMutation(c.config, OpDelete) return &PostDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *PostClient) DeleteOne(po *Post) *PostDeleteOne { return c.DeleteOneID(po.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *PostClient) DeleteOneID(id int) *PostDeleteOne { builder := c.Delete().Where(post.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &PostDeleteOne{builder} } // Query returns a query builder for Post. func (c *PostClient) Query() *PostQuery { return &PostQuery{ config: c.config, ctx: &QueryContext{Type: TypePost}, inters: c.Interceptors(), } } // Get returns a Post entity by its id. func (c *PostClient) Get(ctx context.Context, id int) (*Post, error) { return c.Query().Where(post.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *PostClient) GetX(ctx context.Context, id int) *Post { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryContents queries the contents edge of a Post. func (c *PostClient) QueryContents(po *Post) *PostContentQuery { query := (&PostContentClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := po.ID step := sqlgraph.NewStep( sqlgraph.From(post.Table, post.FieldID, id), sqlgraph.To(postcontent.Table, postcontent.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, post.ContentsTable, post.ContentsColumn), ) fromV = sqlgraph.Neighbors(po.driver.Dialect(), step) return fromV, nil } return query } // QueryContributors queries the contributors edge of a Post. func (c *PostClient) QueryContributors(po *Post) *PostContributorQuery { query := (&PostContributorClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := po.ID step := sqlgraph.NewStep( sqlgraph.From(post.Table, post.FieldID, id), sqlgraph.To(postcontributor.Table, postcontributor.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, post.ContributorsTable, post.ContributorsColumn), ) fromV = sqlgraph.Neighbors(po.driver.Dialect(), step) return fromV, nil } return query } // QueryCategory queries the category edge of a Post. func (c *PostClient) QueryCategory(po *Post) *CategoryQuery { query := (&CategoryClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := po.ID step := sqlgraph.NewStep( sqlgraph.From(post.Table, post.FieldID, id), sqlgraph.To(category.Table, category.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, post.CategoryTable, post.CategoryColumn), ) fromV = sqlgraph.Neighbors(po.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *PostClient) Hooks() []Hook { return c.hooks.Post } // Interceptors returns the client interceptors. func (c *PostClient) Interceptors() []Interceptor { return c.inters.Post } func (c *PostClient) mutate(ctx context.Context, m *PostMutation) (Value, error) { switch m.Op() { case OpCreate: return (&PostCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&PostUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&PostDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown Post mutation op: %q", m.Op()) } } // PostContentClient is a client for the PostContent schema. type PostContentClient struct { config } // NewPostContentClient returns a client for the PostContent from the given config. func NewPostContentClient(c config) *PostContentClient { return &PostContentClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `postcontent.Hooks(f(g(h())))`. func (c *PostContentClient) Use(hooks ...Hook) { c.hooks.PostContent = append(c.hooks.PostContent, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `postcontent.Intercept(f(g(h())))`. func (c *PostContentClient) Intercept(interceptors ...Interceptor) { c.inters.PostContent = append(c.inters.PostContent, interceptors...) } // Create returns a builder for creating a PostContent entity. func (c *PostContentClient) Create() *PostContentCreate { mutation := newPostContentMutation(c.config, OpCreate) return &PostContentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of PostContent entities. func (c *PostContentClient) CreateBulk(builders ...*PostContentCreate) *PostContentCreateBulk { return &PostContentCreateBulk{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 *PostContentClient) MapCreateBulk(slice any, setFunc func(*PostContentCreate, int)) *PostContentCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &PostContentCreateBulk{err: fmt.Errorf("calling to PostContentClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*PostContentCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &PostContentCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for PostContent. func (c *PostContentClient) Update() *PostContentUpdate { mutation := newPostContentMutation(c.config, OpUpdate) return &PostContentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *PostContentClient) UpdateOne(pc *PostContent) *PostContentUpdateOne { mutation := newPostContentMutation(c.config, OpUpdateOne, withPostContent(pc)) return &PostContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *PostContentClient) UpdateOneID(id int) *PostContentUpdateOne { mutation := newPostContentMutation(c.config, OpUpdateOne, withPostContentID(id)) return &PostContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for PostContent. func (c *PostContentClient) Delete() *PostContentDelete { mutation := newPostContentMutation(c.config, OpDelete) return &PostContentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *PostContentClient) DeleteOne(pc *PostContent) *PostContentDeleteOne { return c.DeleteOneID(pc.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *PostContentClient) DeleteOneID(id int) *PostContentDeleteOne { builder := c.Delete().Where(postcontent.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &PostContentDeleteOne{builder} } // Query returns a query builder for PostContent. func (c *PostContentClient) Query() *PostContentQuery { return &PostContentQuery{ config: c.config, ctx: &QueryContext{Type: TypePostContent}, inters: c.Interceptors(), } } // Get returns a PostContent entity by its id. func (c *PostContentClient) Get(ctx context.Context, id int) (*PostContent, error) { return c.Query().Where(postcontent.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *PostContentClient) GetX(ctx context.Context, id int) *PostContent { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryPost queries the post edge of a PostContent. func (c *PostContentClient) QueryPost(pc *PostContent) *PostQuery { query := (&PostClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := pc.ID step := sqlgraph.NewStep( sqlgraph.From(postcontent.Table, postcontent.FieldID, id), sqlgraph.To(post.Table, post.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, postcontent.PostTable, postcontent.PostColumn), ) fromV = sqlgraph.Neighbors(pc.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *PostContentClient) Hooks() []Hook { return c.hooks.PostContent } // Interceptors returns the client interceptors. func (c *PostContentClient) Interceptors() []Interceptor { return c.inters.PostContent } func (c *PostContentClient) mutate(ctx context.Context, m *PostContentMutation) (Value, error) { switch m.Op() { case OpCreate: return (&PostContentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&PostContentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&PostContentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&PostContentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown PostContent mutation op: %q", m.Op()) } } // PostContributorClient is a client for the PostContributor schema. type PostContributorClient struct { config } // NewPostContributorClient returns a client for the PostContributor from the given config. func NewPostContributorClient(c config) *PostContributorClient { return &PostContributorClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `postcontributor.Hooks(f(g(h())))`. func (c *PostContributorClient) Use(hooks ...Hook) { c.hooks.PostContributor = append(c.hooks.PostContributor, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `postcontributor.Intercept(f(g(h())))`. func (c *PostContributorClient) Intercept(interceptors ...Interceptor) { c.inters.PostContributor = append(c.inters.PostContributor, interceptors...) } // Create returns a builder for creating a PostContributor entity. func (c *PostContributorClient) Create() *PostContributorCreate { mutation := newPostContributorMutation(c.config, OpCreate) return &PostContributorCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of PostContributor entities. func (c *PostContributorClient) CreateBulk(builders ...*PostContributorCreate) *PostContributorCreateBulk { return &PostContributorCreateBulk{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 *PostContributorClient) MapCreateBulk(slice any, setFunc func(*PostContributorCreate, int)) *PostContributorCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &PostContributorCreateBulk{err: fmt.Errorf("calling to PostContributorClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*PostContributorCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &PostContributorCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for PostContributor. func (c *PostContributorClient) Update() *PostContributorUpdate { mutation := newPostContributorMutation(c.config, OpUpdate) return &PostContributorUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *PostContributorClient) UpdateOne(pc *PostContributor) *PostContributorUpdateOne { mutation := newPostContributorMutation(c.config, OpUpdateOne, withPostContributor(pc)) return &PostContributorUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *PostContributorClient) UpdateOneID(id int) *PostContributorUpdateOne { mutation := newPostContributorMutation(c.config, OpUpdateOne, withPostContributorID(id)) return &PostContributorUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for PostContributor. func (c *PostContributorClient) Delete() *PostContributorDelete { mutation := newPostContributorMutation(c.config, OpDelete) return &PostContributorDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *PostContributorClient) DeleteOne(pc *PostContributor) *PostContributorDeleteOne { return c.DeleteOneID(pc.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *PostContributorClient) DeleteOneID(id int) *PostContributorDeleteOne { builder := c.Delete().Where(postcontributor.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &PostContributorDeleteOne{builder} } // Query returns a query builder for PostContributor. func (c *PostContributorClient) Query() *PostContributorQuery { return &PostContributorQuery{ config: c.config, ctx: &QueryContext{Type: TypePostContributor}, inters: c.Interceptors(), } } // Get returns a PostContributor entity by its id. func (c *PostContributorClient) Get(ctx context.Context, id int) (*PostContributor, error) { return c.Query().Where(postcontributor.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *PostContributorClient) GetX(ctx context.Context, id int) *PostContributor { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryPost queries the post edge of a PostContributor. func (c *PostContributorClient) QueryPost(pc *PostContributor) *PostQuery { query := (&PostClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := pc.ID step := sqlgraph.NewStep( sqlgraph.From(postcontributor.Table, postcontributor.FieldID, id), sqlgraph.To(post.Table, post.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, postcontributor.PostTable, postcontributor.PostColumn), ) fromV = sqlgraph.Neighbors(pc.driver.Dialect(), step) return fromV, nil } return query } // QueryContributor queries the contributor edge of a PostContributor. func (c *PostContributorClient) QueryContributor(pc *PostContributor) *ContributorQuery { query := (&ContributorClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := pc.ID step := sqlgraph.NewStep( sqlgraph.From(postcontributor.Table, postcontributor.FieldID, id), sqlgraph.To(contributor.Table, contributor.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, postcontributor.ContributorTable, postcontributor.ContributorColumn), ) fromV = sqlgraph.Neighbors(pc.driver.Dialect(), step) return fromV, nil } return query } // QueryRole queries the role edge of a PostContributor. func (c *PostContributorClient) QueryRole(pc *PostContributor) *ContributorRoleQuery { query := (&ContributorRoleClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := pc.ID step := sqlgraph.NewStep( sqlgraph.From(postcontributor.Table, postcontributor.FieldID, id), sqlgraph.To(contributorrole.Table, contributorrole.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, postcontributor.RoleTable, postcontributor.RoleColumn), ) fromV = sqlgraph.Neighbors(pc.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *PostContributorClient) Hooks() []Hook { return c.hooks.PostContributor } // Interceptors returns the client interceptors. func (c *PostContributorClient) Interceptors() []Interceptor { return c.inters.PostContributor } func (c *PostContributorClient) mutate(ctx context.Context, m *PostContributorMutation) (Value, error) { switch m.Op() { case OpCreate: return (&PostContributorCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&PostContributorUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&PostContributorUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&PostContributorDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown PostContributor mutation op: %q", m.Op()) } } // RoleClient is a client for the Role schema. type RoleClient struct { config } // NewRoleClient returns a client for the Role from the given config. func NewRoleClient(c config) *RoleClient { return &RoleClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `role.Hooks(f(g(h())))`. func (c *RoleClient) Use(hooks ...Hook) { c.hooks.Role = append(c.hooks.Role, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `role.Intercept(f(g(h())))`. func (c *RoleClient) Intercept(interceptors ...Interceptor) { c.inters.Role = append(c.inters.Role, interceptors...) } // Create returns a builder for creating a Role entity. func (c *RoleClient) Create() *RoleCreate { mutation := newRoleMutation(c.config, OpCreate) return &RoleCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Role entities. func (c *RoleClient) CreateBulk(builders ...*RoleCreate) *RoleCreateBulk { return &RoleCreateBulk{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 *RoleClient) MapCreateBulk(slice any, setFunc func(*RoleCreate, int)) *RoleCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &RoleCreateBulk{err: fmt.Errorf("calling to RoleClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*RoleCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &RoleCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Role. func (c *RoleClient) Update() *RoleUpdate { mutation := newRoleMutation(c.config, OpUpdate) return &RoleUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *RoleClient) UpdateOne(r *Role) *RoleUpdateOne { mutation := newRoleMutation(c.config, OpUpdateOne, withRole(r)) return &RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *RoleClient) UpdateOneID(id int) *RoleUpdateOne { mutation := newRoleMutation(c.config, OpUpdateOne, withRoleID(id)) return &RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Role. func (c *RoleClient) Delete() *RoleDelete { mutation := newRoleMutation(c.config, OpDelete) return &RoleDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *RoleClient) DeleteOne(r *Role) *RoleDeleteOne { return c.DeleteOneID(r.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *RoleClient) DeleteOneID(id int) *RoleDeleteOne { builder := c.Delete().Where(role.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &RoleDeleteOne{builder} } // Query returns a query builder for Role. func (c *RoleClient) Query() *RoleQuery { return &RoleQuery{ config: c.config, ctx: &QueryContext{Type: TypeRole}, inters: c.Interceptors(), } } // Get returns a Role entity by its id. func (c *RoleClient) Get(ctx context.Context, id int) (*Role, error) { return c.Query().Where(role.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *RoleClient) GetX(ctx context.Context, id int) *Role { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryPermissions queries the permissions edge of a Role. func (c *RoleClient) QueryPermissions(r *Role) *PermissionQuery { query := (&PermissionClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := r.ID step := sqlgraph.NewStep( sqlgraph.From(role.Table, role.FieldID, id), sqlgraph.To(permission.Table, permission.FieldID), sqlgraph.Edge(sqlgraph.M2M, false, role.PermissionsTable, role.PermissionsPrimaryKey...), ) fromV = sqlgraph.Neighbors(r.driver.Dialect(), step) return fromV, nil } return query } // QueryUsers queries the users edge of a Role. func (c *RoleClient) QueryUsers(r *Role) *UserQuery { query := (&UserClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := r.ID step := sqlgraph.NewStep( sqlgraph.From(role.Table, role.FieldID, id), sqlgraph.To(user.Table, user.FieldID), sqlgraph.Edge(sqlgraph.M2M, true, role.UsersTable, role.UsersPrimaryKey...), ) fromV = sqlgraph.Neighbors(r.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *RoleClient) Hooks() []Hook { return c.hooks.Role } // Interceptors returns the client interceptors. func (c *RoleClient) Interceptors() []Interceptor { return c.inters.Role } func (c *RoleClient) mutate(ctx context.Context, m *RoleMutation) (Value, error) { switch m.Op() { case OpCreate: return (&RoleCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&RoleUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&RoleDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown Role mutation op: %q", m.Op()) } } // UserClient is a client for the User schema. type UserClient struct { config } // NewUserClient returns a client for the User from the given config. func NewUserClient(c config) *UserClient { return &UserClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`. func (c *UserClient) Use(hooks ...Hook) { c.hooks.User = append(c.hooks.User, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`. func (c *UserClient) Intercept(interceptors ...Interceptor) { c.inters.User = append(c.inters.User, interceptors...) } // Create returns a builder for creating a User entity. func (c *UserClient) Create() *UserCreate { mutation := newUserMutation(c.config, OpCreate) return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of User entities. func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{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 *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*UserCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &UserCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *UserClient) UpdateOne(u *User) *UserUpdateOne { mutation := newUserMutation(c.config, OpUpdateOne, withUser(u)) return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *UserClient) UpdateOneID(id int) *UserUpdateOne { mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id)) return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for User. func (c *UserClient) Delete() *UserDelete { mutation := newUserMutation(c.config, OpDelete) return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *UserClient) DeleteOne(u *User) *UserDeleteOne { return c.DeleteOneID(u.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *UserClient) DeleteOneID(id int) *UserDeleteOne { builder := c.Delete().Where(user.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &UserDeleteOne{builder} } // Query returns a query builder for User. func (c *UserClient) Query() *UserQuery { return &UserQuery{ config: c.config, ctx: &QueryContext{Type: TypeUser}, inters: c.Interceptors(), } } // Get returns a User entity by its id. func (c *UserClient) Get(ctx context.Context, id int) (*User, error) { return c.Query().Where(user.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *UserClient) GetX(ctx context.Context, id int) *User { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryRoles queries the roles edge of a User. func (c *UserClient) QueryRoles(u *User) *RoleQuery { query := (&RoleClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( sqlgraph.From(user.Table, user.FieldID, id), sqlgraph.To(role.Table, role.FieldID), sqlgraph.Edge(sqlgraph.M2M, false, user.RolesTable, user.RolesPrimaryKey...), ) fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) return fromV, nil } return query } // QueryContributors queries the contributors edge of a User. func (c *UserClient) QueryContributors(u *User) *ContributorQuery { query := (&ContributorClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( sqlgraph.From(user.Table, user.FieldID, id), sqlgraph.To(contributor.Table, contributor.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, user.ContributorsTable, user.ContributorsColumn), ) fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) return fromV, nil } return query } // QueryMedia queries the media edge of a User. func (c *UserClient) QueryMedia(u *User) *MediaQuery { query := (&MediaClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( sqlgraph.From(user.Table, user.FieldID, id), sqlgraph.To(media.Table, media.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, user.MediaTable, user.MediaColumn), ) fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *UserClient) Hooks() []Hook { return c.hooks.User } // Interceptors returns the client interceptors. func (c *UserClient) Interceptors() []Interceptor { return c.inters.User } func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { switch m.Op() { case OpCreate: return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) } } // hooks and interceptors per client, for fast access. type ( hooks struct { Category, CategoryContent, Contributor, ContributorRole, ContributorSocialLink, Daily, DailyCategory, DailyCategoryContent, DailyContent, Media, Permission, Post, PostContent, PostContributor, Role, User []ent.Hook } inters struct { Category, CategoryContent, Contributor, ContributorRole, ContributorSocialLink, Daily, DailyCategory, DailyCategoryContent, DailyContent, Media, Permission, Post, PostContent, PostContributor, Role, User []ent.Interceptor } )