// Code generated by ent, DO NOT EDIT. package models import ( "context" "errors" "fmt" "log" "reflect" "juwan-backend/app/community/rpc/internal/models/migrate" "juwan-backend/app/community/rpc/internal/models/commentlikes" "juwan-backend/app/community/rpc/internal/models/comments" "juwan-backend/app/community/rpc/internal/models/postlikes" "juwan-backend/app/community/rpc/internal/models/posts" "entgo.io/ent" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" ) // 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 // CommentLikes is the client for interacting with the CommentLikes builders. CommentLikes *CommentLikesClient // Comments is the client for interacting with the Comments builders. Comments *CommentsClient // PostLikes is the client for interacting with the PostLikes builders. PostLikes *PostLikesClient // Posts is the client for interacting with the Posts builders. Posts *PostsClient } // 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.CommentLikes = NewCommentLikesClient(c.config) c.Comments = NewCommentsClient(c.config) c.PostLikes = NewPostLikesClient(c.config) c.Posts = NewPostsClient(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("models: 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("models: starting a transaction: %w", err) } cfg := c.config cfg.driver = tx return &Tx{ ctx: ctx, config: cfg, CommentLikes: NewCommentLikesClient(cfg), Comments: NewCommentsClient(cfg), PostLikes: NewPostLikesClient(cfg), Posts: NewPostsClient(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, CommentLikes: NewCommentLikesClient(cfg), Comments: NewCommentsClient(cfg), PostLikes: NewPostLikesClient(cfg), Posts: NewPostsClient(cfg), }, nil } // Debug returns a new debug-client. It's used to get verbose logging on specific operations. // // client.Debug(). // CommentLikes. // 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) { c.CommentLikes.Use(hooks...) c.Comments.Use(hooks...) c.PostLikes.Use(hooks...) c.Posts.Use(hooks...) } // Intercept adds the query interceptors to all the entity clients. // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. func (c *Client) Intercept(interceptors ...Interceptor) { c.CommentLikes.Intercept(interceptors...) c.Comments.Intercept(interceptors...) c.PostLikes.Intercept(interceptors...) c.Posts.Intercept(interceptors...) } // Mutate implements the ent.Mutator interface. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { switch m := m.(type) { case *CommentLikesMutation: return c.CommentLikes.mutate(ctx, m) case *CommentsMutation: return c.Comments.mutate(ctx, m) case *PostLikesMutation: return c.PostLikes.mutate(ctx, m) case *PostsMutation: return c.Posts.mutate(ctx, m) default: return nil, fmt.Errorf("models: unknown mutation type %T", m) } } // CommentLikesClient is a client for the CommentLikes schema. type CommentLikesClient struct { config } // NewCommentLikesClient returns a client for the CommentLikes from the given config. func NewCommentLikesClient(c config) *CommentLikesClient { return &CommentLikesClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `commentlikes.Hooks(f(g(h())))`. func (c *CommentLikesClient) Use(hooks ...Hook) { c.hooks.CommentLikes = append(c.hooks.CommentLikes, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `commentlikes.Intercept(f(g(h())))`. func (c *CommentLikesClient) Intercept(interceptors ...Interceptor) { c.inters.CommentLikes = append(c.inters.CommentLikes, interceptors...) } // Create returns a builder for creating a CommentLikes entity. func (c *CommentLikesClient) Create() *CommentLikesCreate { mutation := newCommentLikesMutation(c.config, OpCreate) return &CommentLikesCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of CommentLikes entities. func (c *CommentLikesClient) CreateBulk(builders ...*CommentLikesCreate) *CommentLikesCreateBulk { return &CommentLikesCreateBulk{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 *CommentLikesClient) MapCreateBulk(slice any, setFunc func(*CommentLikesCreate, int)) *CommentLikesCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &CommentLikesCreateBulk{err: fmt.Errorf("calling to CommentLikesClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*CommentLikesCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &CommentLikesCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for CommentLikes. func (c *CommentLikesClient) Update() *CommentLikesUpdate { mutation := newCommentLikesMutation(c.config, OpUpdate) return &CommentLikesUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *CommentLikesClient) UpdateOne(_m *CommentLikes) *CommentLikesUpdateOne { mutation := newCommentLikesMutation(c.config, OpUpdateOne, withCommentLikes(_m)) return &CommentLikesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *CommentLikesClient) UpdateOneID(id int64) *CommentLikesUpdateOne { mutation := newCommentLikesMutation(c.config, OpUpdateOne, withCommentLikesID(id)) return &CommentLikesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for CommentLikes. func (c *CommentLikesClient) Delete() *CommentLikesDelete { mutation := newCommentLikesMutation(c.config, OpDelete) return &CommentLikesDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *CommentLikesClient) DeleteOne(_m *CommentLikes) *CommentLikesDeleteOne { return c.DeleteOneID(_m.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *CommentLikesClient) DeleteOneID(id int64) *CommentLikesDeleteOne { builder := c.Delete().Where(commentlikes.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &CommentLikesDeleteOne{builder} } // Query returns a query builder for CommentLikes. func (c *CommentLikesClient) Query() *CommentLikesQuery { return &CommentLikesQuery{ config: c.config, ctx: &QueryContext{Type: TypeCommentLikes}, inters: c.Interceptors(), } } // Get returns a CommentLikes entity by its id. func (c *CommentLikesClient) Get(ctx context.Context, id int64) (*CommentLikes, error) { return c.Query().Where(commentlikes.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *CommentLikesClient) GetX(ctx context.Context, id int64) *CommentLikes { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *CommentLikesClient) Hooks() []Hook { return c.hooks.CommentLikes } // Interceptors returns the client interceptors. func (c *CommentLikesClient) Interceptors() []Interceptor { return c.inters.CommentLikes } func (c *CommentLikesClient) mutate(ctx context.Context, m *CommentLikesMutation) (Value, error) { switch m.Op() { case OpCreate: return (&CommentLikesCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&CommentLikesUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&CommentLikesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&CommentLikesDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("models: unknown CommentLikes mutation op: %q", m.Op()) } } // CommentsClient is a client for the Comments schema. type CommentsClient struct { config } // NewCommentsClient returns a client for the Comments from the given config. func NewCommentsClient(c config) *CommentsClient { return &CommentsClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `comments.Hooks(f(g(h())))`. func (c *CommentsClient) Use(hooks ...Hook) { c.hooks.Comments = append(c.hooks.Comments, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `comments.Intercept(f(g(h())))`. func (c *CommentsClient) Intercept(interceptors ...Interceptor) { c.inters.Comments = append(c.inters.Comments, interceptors...) } // Create returns a builder for creating a Comments entity. func (c *CommentsClient) Create() *CommentsCreate { mutation := newCommentsMutation(c.config, OpCreate) return &CommentsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Comments entities. func (c *CommentsClient) CreateBulk(builders ...*CommentsCreate) *CommentsCreateBulk { return &CommentsCreateBulk{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 *CommentsClient) MapCreateBulk(slice any, setFunc func(*CommentsCreate, int)) *CommentsCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &CommentsCreateBulk{err: fmt.Errorf("calling to CommentsClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*CommentsCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &CommentsCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Comments. func (c *CommentsClient) Update() *CommentsUpdate { mutation := newCommentsMutation(c.config, OpUpdate) return &CommentsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *CommentsClient) UpdateOne(_m *Comments) *CommentsUpdateOne { mutation := newCommentsMutation(c.config, OpUpdateOne, withComments(_m)) return &CommentsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *CommentsClient) UpdateOneID(id int64) *CommentsUpdateOne { mutation := newCommentsMutation(c.config, OpUpdateOne, withCommentsID(id)) return &CommentsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Comments. func (c *CommentsClient) Delete() *CommentsDelete { mutation := newCommentsMutation(c.config, OpDelete) return &CommentsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *CommentsClient) DeleteOne(_m *Comments) *CommentsDeleteOne { return c.DeleteOneID(_m.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *CommentsClient) DeleteOneID(id int64) *CommentsDeleteOne { builder := c.Delete().Where(comments.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &CommentsDeleteOne{builder} } // Query returns a query builder for Comments. func (c *CommentsClient) Query() *CommentsQuery { return &CommentsQuery{ config: c.config, ctx: &QueryContext{Type: TypeComments}, inters: c.Interceptors(), } } // Get returns a Comments entity by its id. func (c *CommentsClient) Get(ctx context.Context, id int64) (*Comments, error) { return c.Query().Where(comments.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *CommentsClient) GetX(ctx context.Context, id int64) *Comments { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *CommentsClient) Hooks() []Hook { return c.hooks.Comments } // Interceptors returns the client interceptors. func (c *CommentsClient) Interceptors() []Interceptor { return c.inters.Comments } func (c *CommentsClient) mutate(ctx context.Context, m *CommentsMutation) (Value, error) { switch m.Op() { case OpCreate: return (&CommentsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&CommentsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&CommentsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&CommentsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("models: unknown Comments mutation op: %q", m.Op()) } } // PostLikesClient is a client for the PostLikes schema. type PostLikesClient struct { config } // NewPostLikesClient returns a client for the PostLikes from the given config. func NewPostLikesClient(c config) *PostLikesClient { return &PostLikesClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `postlikes.Hooks(f(g(h())))`. func (c *PostLikesClient) Use(hooks ...Hook) { c.hooks.PostLikes = append(c.hooks.PostLikes, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `postlikes.Intercept(f(g(h())))`. func (c *PostLikesClient) Intercept(interceptors ...Interceptor) { c.inters.PostLikes = append(c.inters.PostLikes, interceptors...) } // Create returns a builder for creating a PostLikes entity. func (c *PostLikesClient) Create() *PostLikesCreate { mutation := newPostLikesMutation(c.config, OpCreate) return &PostLikesCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of PostLikes entities. func (c *PostLikesClient) CreateBulk(builders ...*PostLikesCreate) *PostLikesCreateBulk { return &PostLikesCreateBulk{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 *PostLikesClient) MapCreateBulk(slice any, setFunc func(*PostLikesCreate, int)) *PostLikesCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &PostLikesCreateBulk{err: fmt.Errorf("calling to PostLikesClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*PostLikesCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &PostLikesCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for PostLikes. func (c *PostLikesClient) Update() *PostLikesUpdate { mutation := newPostLikesMutation(c.config, OpUpdate) return &PostLikesUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *PostLikesClient) UpdateOne(_m *PostLikes) *PostLikesUpdateOne { mutation := newPostLikesMutation(c.config, OpUpdateOne, withPostLikes(_m)) return &PostLikesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *PostLikesClient) UpdateOneID(id int64) *PostLikesUpdateOne { mutation := newPostLikesMutation(c.config, OpUpdateOne, withPostLikesID(id)) return &PostLikesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for PostLikes. func (c *PostLikesClient) Delete() *PostLikesDelete { mutation := newPostLikesMutation(c.config, OpDelete) return &PostLikesDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *PostLikesClient) DeleteOne(_m *PostLikes) *PostLikesDeleteOne { return c.DeleteOneID(_m.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *PostLikesClient) DeleteOneID(id int64) *PostLikesDeleteOne { builder := c.Delete().Where(postlikes.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &PostLikesDeleteOne{builder} } // Query returns a query builder for PostLikes. func (c *PostLikesClient) Query() *PostLikesQuery { return &PostLikesQuery{ config: c.config, ctx: &QueryContext{Type: TypePostLikes}, inters: c.Interceptors(), } } // Get returns a PostLikes entity by its id. func (c *PostLikesClient) Get(ctx context.Context, id int64) (*PostLikes, error) { return c.Query().Where(postlikes.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *PostLikesClient) GetX(ctx context.Context, id int64) *PostLikes { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *PostLikesClient) Hooks() []Hook { return c.hooks.PostLikes } // Interceptors returns the client interceptors. func (c *PostLikesClient) Interceptors() []Interceptor { return c.inters.PostLikes } func (c *PostLikesClient) mutate(ctx context.Context, m *PostLikesMutation) (Value, error) { switch m.Op() { case OpCreate: return (&PostLikesCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&PostLikesUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&PostLikesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&PostLikesDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("models: unknown PostLikes mutation op: %q", m.Op()) } } // PostsClient is a client for the Posts schema. type PostsClient struct { config } // NewPostsClient returns a client for the Posts from the given config. func NewPostsClient(c config) *PostsClient { return &PostsClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `posts.Hooks(f(g(h())))`. func (c *PostsClient) Use(hooks ...Hook) { c.hooks.Posts = append(c.hooks.Posts, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `posts.Intercept(f(g(h())))`. func (c *PostsClient) Intercept(interceptors ...Interceptor) { c.inters.Posts = append(c.inters.Posts, interceptors...) } // Create returns a builder for creating a Posts entity. func (c *PostsClient) Create() *PostsCreate { mutation := newPostsMutation(c.config, OpCreate) return &PostsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Posts entities. func (c *PostsClient) CreateBulk(builders ...*PostsCreate) *PostsCreateBulk { return &PostsCreateBulk{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 *PostsClient) MapCreateBulk(slice any, setFunc func(*PostsCreate, int)) *PostsCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &PostsCreateBulk{err: fmt.Errorf("calling to PostsClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*PostsCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &PostsCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Posts. func (c *PostsClient) Update() *PostsUpdate { mutation := newPostsMutation(c.config, OpUpdate) return &PostsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *PostsClient) UpdateOne(_m *Posts) *PostsUpdateOne { mutation := newPostsMutation(c.config, OpUpdateOne, withPosts(_m)) return &PostsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *PostsClient) UpdateOneID(id int64) *PostsUpdateOne { mutation := newPostsMutation(c.config, OpUpdateOne, withPostsID(id)) return &PostsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Posts. func (c *PostsClient) Delete() *PostsDelete { mutation := newPostsMutation(c.config, OpDelete) return &PostsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *PostsClient) DeleteOne(_m *Posts) *PostsDeleteOne { return c.DeleteOneID(_m.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *PostsClient) DeleteOneID(id int64) *PostsDeleteOne { builder := c.Delete().Where(posts.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &PostsDeleteOne{builder} } // Query returns a query builder for Posts. func (c *PostsClient) Query() *PostsQuery { return &PostsQuery{ config: c.config, ctx: &QueryContext{Type: TypePosts}, inters: c.Interceptors(), } } // Get returns a Posts entity by its id. func (c *PostsClient) Get(ctx context.Context, id int64) (*Posts, error) { return c.Query().Where(posts.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *PostsClient) GetX(ctx context.Context, id int64) *Posts { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *PostsClient) Hooks() []Hook { return c.hooks.Posts } // Interceptors returns the client interceptors. func (c *PostsClient) Interceptors() []Interceptor { return c.inters.Posts } func (c *PostsClient) mutate(ctx context.Context, m *PostsMutation) (Value, error) { switch m.Op() { case OpCreate: return (&PostsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&PostsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&PostsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&PostsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("models: unknown Posts mutation op: %q", m.Op()) } } // hooks and interceptors per client, for fast access. type ( hooks struct { CommentLikes, Comments, PostLikes, Posts []ent.Hook } inters struct { CommentLikes, Comments, PostLikes, Posts []ent.Interceptor } )