versia-go/ent/client.go

1248 lines
42 KiB
Go
Raw Normal View History

2024-08-11 03:51:22 +02:00
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"log"
"reflect"
"github.com/google/uuid"
"github.com/lysand-org/versia-go/ent/migrate"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/lysand-org/versia-go/ent/attachment"
"github.com/lysand-org/versia-go/ent/follow"
"github.com/lysand-org/versia-go/ent/image"
"github.com/lysand-org/versia-go/ent/note"
"github.com/lysand-org/versia-go/ent/servermetadata"
"github.com/lysand-org/versia-go/ent/user"
)
// 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
// Attachment is the client for interacting with the Attachment builders.
Attachment *AttachmentClient
// Follow is the client for interacting with the Follow builders.
Follow *FollowClient
// Image is the client for interacting with the Image builders.
Image *ImageClient
// Note is the client for interacting with the Note builders.
Note *NoteClient
// ServerMetadata is the client for interacting with the ServerMetadata builders.
ServerMetadata *ServerMetadataClient
// 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.Attachment = NewAttachmentClient(c.config)
c.Follow = NewFollowClient(c.config)
c.Image = NewImageClient(c.config)
c.Note = NewNoteClient(c.config)
c.ServerMetadata = NewServerMetadataClient(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,
Attachment: NewAttachmentClient(cfg),
Follow: NewFollowClient(cfg),
Image: NewImageClient(cfg),
Note: NewNoteClient(cfg),
ServerMetadata: NewServerMetadataClient(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,
Attachment: NewAttachmentClient(cfg),
Follow: NewFollowClient(cfg),
Image: NewImageClient(cfg),
Note: NewNoteClient(cfg),
ServerMetadata: NewServerMetadataClient(cfg),
User: NewUserClient(cfg),
}, nil
}
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
// client.Debug().
// Attachment.
// 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.Attachment, c.Follow, c.Image, c.Note, c.ServerMetadata, 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.Attachment, c.Follow, c.Image, c.Note, c.ServerMetadata, 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 *AttachmentMutation:
return c.Attachment.mutate(ctx, m)
case *FollowMutation:
return c.Follow.mutate(ctx, m)
case *ImageMutation:
return c.Image.mutate(ctx, m)
case *NoteMutation:
return c.Note.mutate(ctx, m)
case *ServerMetadataMutation:
return c.ServerMetadata.mutate(ctx, m)
case *UserMutation:
return c.User.mutate(ctx, m)
default:
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
}
}
// AttachmentClient is a client for the Attachment schema.
type AttachmentClient struct {
config
}
// NewAttachmentClient returns a client for the Attachment from the given config.
func NewAttachmentClient(c config) *AttachmentClient {
return &AttachmentClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `attachment.Hooks(f(g(h())))`.
func (c *AttachmentClient) Use(hooks ...Hook) {
c.hooks.Attachment = append(c.hooks.Attachment, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `attachment.Intercept(f(g(h())))`.
func (c *AttachmentClient) Intercept(interceptors ...Interceptor) {
c.inters.Attachment = append(c.inters.Attachment, interceptors...)
}
// Create returns a builder for creating a Attachment entity.
func (c *AttachmentClient) Create() *AttachmentCreate {
mutation := newAttachmentMutation(c.config, OpCreate)
return &AttachmentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Attachment entities.
func (c *AttachmentClient) CreateBulk(builders ...*AttachmentCreate) *AttachmentCreateBulk {
return &AttachmentCreateBulk{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 *AttachmentClient) MapCreateBulk(slice any, setFunc func(*AttachmentCreate, int)) *AttachmentCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &AttachmentCreateBulk{err: fmt.Errorf("calling to AttachmentClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*AttachmentCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &AttachmentCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Attachment.
func (c *AttachmentClient) Update() *AttachmentUpdate {
mutation := newAttachmentMutation(c.config, OpUpdate)
return &AttachmentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *AttachmentClient) UpdateOne(a *Attachment) *AttachmentUpdateOne {
mutation := newAttachmentMutation(c.config, OpUpdateOne, withAttachment(a))
return &AttachmentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *AttachmentClient) UpdateOneID(id uuid.UUID) *AttachmentUpdateOne {
mutation := newAttachmentMutation(c.config, OpUpdateOne, withAttachmentID(id))
return &AttachmentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Attachment.
func (c *AttachmentClient) Delete() *AttachmentDelete {
mutation := newAttachmentMutation(c.config, OpDelete)
return &AttachmentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *AttachmentClient) DeleteOne(a *Attachment) *AttachmentDeleteOne {
return c.DeleteOneID(a.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *AttachmentClient) DeleteOneID(id uuid.UUID) *AttachmentDeleteOne {
builder := c.Delete().Where(attachment.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &AttachmentDeleteOne{builder}
}
// Query returns a query builder for Attachment.
func (c *AttachmentClient) Query() *AttachmentQuery {
return &AttachmentQuery{
config: c.config,
ctx: &QueryContext{Type: TypeAttachment},
inters: c.Interceptors(),
}
}
// Get returns a Attachment entity by its id.
func (c *AttachmentClient) Get(ctx context.Context, id uuid.UUID) (*Attachment, error) {
return c.Query().Where(attachment.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *AttachmentClient) GetX(ctx context.Context, id uuid.UUID) *Attachment {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryAuthor queries the author edge of a Attachment.
func (c *AttachmentClient) QueryAuthor(a *Attachment) *UserQuery {
query := (&UserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := a.ID
step := sqlgraph.NewStep(
sqlgraph.From(attachment.Table, attachment.FieldID, id),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, attachment.AuthorTable, attachment.AuthorColumn),
)
fromV = sqlgraph.Neighbors(a.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *AttachmentClient) Hooks() []Hook {
return c.hooks.Attachment
}
// Interceptors returns the client interceptors.
func (c *AttachmentClient) Interceptors() []Interceptor {
return c.inters.Attachment
}
func (c *AttachmentClient) mutate(ctx context.Context, m *AttachmentMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&AttachmentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&AttachmentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&AttachmentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&AttachmentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown Attachment mutation op: %q", m.Op())
}
}
// FollowClient is a client for the Follow schema.
type FollowClient struct {
config
}
// NewFollowClient returns a client for the Follow from the given config.
func NewFollowClient(c config) *FollowClient {
return &FollowClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `follow.Hooks(f(g(h())))`.
func (c *FollowClient) Use(hooks ...Hook) {
c.hooks.Follow = append(c.hooks.Follow, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `follow.Intercept(f(g(h())))`.
func (c *FollowClient) Intercept(interceptors ...Interceptor) {
c.inters.Follow = append(c.inters.Follow, interceptors...)
}
// Create returns a builder for creating a Follow entity.
func (c *FollowClient) Create() *FollowCreate {
mutation := newFollowMutation(c.config, OpCreate)
return &FollowCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Follow entities.
func (c *FollowClient) CreateBulk(builders ...*FollowCreate) *FollowCreateBulk {
return &FollowCreateBulk{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 *FollowClient) MapCreateBulk(slice any, setFunc func(*FollowCreate, int)) *FollowCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &FollowCreateBulk{err: fmt.Errorf("calling to FollowClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*FollowCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &FollowCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Follow.
func (c *FollowClient) Update() *FollowUpdate {
mutation := newFollowMutation(c.config, OpUpdate)
return &FollowUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *FollowClient) UpdateOne(f *Follow) *FollowUpdateOne {
mutation := newFollowMutation(c.config, OpUpdateOne, withFollow(f))
return &FollowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *FollowClient) UpdateOneID(id uuid.UUID) *FollowUpdateOne {
mutation := newFollowMutation(c.config, OpUpdateOne, withFollowID(id))
return &FollowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Follow.
func (c *FollowClient) Delete() *FollowDelete {
mutation := newFollowMutation(c.config, OpDelete)
return &FollowDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *FollowClient) DeleteOne(f *Follow) *FollowDeleteOne {
return c.DeleteOneID(f.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *FollowClient) DeleteOneID(id uuid.UUID) *FollowDeleteOne {
builder := c.Delete().Where(follow.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &FollowDeleteOne{builder}
}
// Query returns a query builder for Follow.
func (c *FollowClient) Query() *FollowQuery {
return &FollowQuery{
config: c.config,
ctx: &QueryContext{Type: TypeFollow},
inters: c.Interceptors(),
}
}
// Get returns a Follow entity by its id.
func (c *FollowClient) Get(ctx context.Context, id uuid.UUID) (*Follow, error) {
return c.Query().Where(follow.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *FollowClient) GetX(ctx context.Context, id uuid.UUID) *Follow {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryFollower queries the follower edge of a Follow.
func (c *FollowClient) QueryFollower(f *Follow) *UserQuery {
query := (&UserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := f.ID
step := sqlgraph.NewStep(
sqlgraph.From(follow.Table, follow.FieldID, id),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, follow.FollowerTable, follow.FollowerColumn),
)
fromV = sqlgraph.Neighbors(f.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryFollowee queries the followee edge of a Follow.
func (c *FollowClient) QueryFollowee(f *Follow) *UserQuery {
query := (&UserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := f.ID
step := sqlgraph.NewStep(
sqlgraph.From(follow.Table, follow.FieldID, id),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, follow.FolloweeTable, follow.FolloweeColumn),
)
fromV = sqlgraph.Neighbors(f.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *FollowClient) Hooks() []Hook {
return c.hooks.Follow
}
// Interceptors returns the client interceptors.
func (c *FollowClient) Interceptors() []Interceptor {
return c.inters.Follow
}
func (c *FollowClient) mutate(ctx context.Context, m *FollowMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&FollowCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&FollowUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&FollowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&FollowDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown Follow mutation op: %q", m.Op())
}
}
// ImageClient is a client for the Image schema.
type ImageClient struct {
config
}
// NewImageClient returns a client for the Image from the given config.
func NewImageClient(c config) *ImageClient {
return &ImageClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `image.Hooks(f(g(h())))`.
func (c *ImageClient) Use(hooks ...Hook) {
c.hooks.Image = append(c.hooks.Image, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `image.Intercept(f(g(h())))`.
func (c *ImageClient) Intercept(interceptors ...Interceptor) {
c.inters.Image = append(c.inters.Image, interceptors...)
}
// Create returns a builder for creating a Image entity.
func (c *ImageClient) Create() *ImageCreate {
mutation := newImageMutation(c.config, OpCreate)
return &ImageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Image entities.
func (c *ImageClient) CreateBulk(builders ...*ImageCreate) *ImageCreateBulk {
return &ImageCreateBulk{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 *ImageClient) MapCreateBulk(slice any, setFunc func(*ImageCreate, int)) *ImageCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &ImageCreateBulk{err: fmt.Errorf("calling to ImageClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*ImageCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &ImageCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Image.
func (c *ImageClient) Update() *ImageUpdate {
mutation := newImageMutation(c.config, OpUpdate)
return &ImageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *ImageClient) UpdateOne(i *Image) *ImageUpdateOne {
mutation := newImageMutation(c.config, OpUpdateOne, withImage(i))
return &ImageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *ImageClient) UpdateOneID(id int) *ImageUpdateOne {
mutation := newImageMutation(c.config, OpUpdateOne, withImageID(id))
return &ImageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Image.
func (c *ImageClient) Delete() *ImageDelete {
mutation := newImageMutation(c.config, OpDelete)
return &ImageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *ImageClient) DeleteOne(i *Image) *ImageDeleteOne {
return c.DeleteOneID(i.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *ImageClient) DeleteOneID(id int) *ImageDeleteOne {
builder := c.Delete().Where(image.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &ImageDeleteOne{builder}
}
// Query returns a query builder for Image.
func (c *ImageClient) Query() *ImageQuery {
return &ImageQuery{
config: c.config,
ctx: &QueryContext{Type: TypeImage},
inters: c.Interceptors(),
}
}
// Get returns a Image entity by its id.
func (c *ImageClient) Get(ctx context.Context, id int) (*Image, error) {
return c.Query().Where(image.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *ImageClient) GetX(ctx context.Context, id int) *Image {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *ImageClient) Hooks() []Hook {
return c.hooks.Image
}
// Interceptors returns the client interceptors.
func (c *ImageClient) Interceptors() []Interceptor {
return c.inters.Image
}
func (c *ImageClient) mutate(ctx context.Context, m *ImageMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&ImageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&ImageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&ImageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&ImageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown Image mutation op: %q", m.Op())
}
}
// NoteClient is a client for the Note schema.
type NoteClient struct {
config
}
// NewNoteClient returns a client for the Note from the given config.
func NewNoteClient(c config) *NoteClient {
return &NoteClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `note.Hooks(f(g(h())))`.
func (c *NoteClient) Use(hooks ...Hook) {
c.hooks.Note = append(c.hooks.Note, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `note.Intercept(f(g(h())))`.
func (c *NoteClient) Intercept(interceptors ...Interceptor) {
c.inters.Note = append(c.inters.Note, interceptors...)
}
// Create returns a builder for creating a Note entity.
func (c *NoteClient) Create() *NoteCreate {
mutation := newNoteMutation(c.config, OpCreate)
return &NoteCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Note entities.
func (c *NoteClient) CreateBulk(builders ...*NoteCreate) *NoteCreateBulk {
return &NoteCreateBulk{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 *NoteClient) MapCreateBulk(slice any, setFunc func(*NoteCreate, int)) *NoteCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &NoteCreateBulk{err: fmt.Errorf("calling to NoteClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*NoteCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &NoteCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Note.
func (c *NoteClient) Update() *NoteUpdate {
mutation := newNoteMutation(c.config, OpUpdate)
return &NoteUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *NoteClient) UpdateOne(n *Note) *NoteUpdateOne {
mutation := newNoteMutation(c.config, OpUpdateOne, withNote(n))
return &NoteUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *NoteClient) UpdateOneID(id uuid.UUID) *NoteUpdateOne {
mutation := newNoteMutation(c.config, OpUpdateOne, withNoteID(id))
return &NoteUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Note.
func (c *NoteClient) Delete() *NoteDelete {
mutation := newNoteMutation(c.config, OpDelete)
return &NoteDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *NoteClient) DeleteOne(n *Note) *NoteDeleteOne {
return c.DeleteOneID(n.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *NoteClient) DeleteOneID(id uuid.UUID) *NoteDeleteOne {
builder := c.Delete().Where(note.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &NoteDeleteOne{builder}
}
// Query returns a query builder for Note.
func (c *NoteClient) Query() *NoteQuery {
return &NoteQuery{
config: c.config,
ctx: &QueryContext{Type: TypeNote},
inters: c.Interceptors(),
}
}
// Get returns a Note entity by its id.
func (c *NoteClient) Get(ctx context.Context, id uuid.UUID) (*Note, error) {
return c.Query().Where(note.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *NoteClient) GetX(ctx context.Context, id uuid.UUID) *Note {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryAuthor queries the author edge of a Note.
func (c *NoteClient) QueryAuthor(n *Note) *UserQuery {
query := (&UserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := n.ID
step := sqlgraph.NewStep(
sqlgraph.From(note.Table, note.FieldID, id),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, note.AuthorTable, note.AuthorColumn),
)
fromV = sqlgraph.Neighbors(n.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryMentions queries the mentions edge of a Note.
func (c *NoteClient) QueryMentions(n *Note) *UserQuery {
query := (&UserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := n.ID
step := sqlgraph.NewStep(
sqlgraph.From(note.Table, note.FieldID, id),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, note.MentionsTable, note.MentionsPrimaryKey...),
)
fromV = sqlgraph.Neighbors(n.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryAttachments queries the attachments edge of a Note.
func (c *NoteClient) QueryAttachments(n *Note) *AttachmentQuery {
query := (&AttachmentClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := n.ID
step := sqlgraph.NewStep(
sqlgraph.From(note.Table, note.FieldID, id),
sqlgraph.To(attachment.Table, attachment.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, note.AttachmentsTable, note.AttachmentsColumn),
)
fromV = sqlgraph.Neighbors(n.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *NoteClient) Hooks() []Hook {
return c.hooks.Note
}
// Interceptors returns the client interceptors.
func (c *NoteClient) Interceptors() []Interceptor {
return c.inters.Note
}
func (c *NoteClient) mutate(ctx context.Context, m *NoteMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&NoteCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&NoteUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&NoteUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&NoteDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown Note mutation op: %q", m.Op())
}
}
// ServerMetadataClient is a client for the ServerMetadata schema.
type ServerMetadataClient struct {
config
}
// NewServerMetadataClient returns a client for the ServerMetadata from the given config.
func NewServerMetadataClient(c config) *ServerMetadataClient {
return &ServerMetadataClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `servermetadata.Hooks(f(g(h())))`.
func (c *ServerMetadataClient) Use(hooks ...Hook) {
c.hooks.ServerMetadata = append(c.hooks.ServerMetadata, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `servermetadata.Intercept(f(g(h())))`.
func (c *ServerMetadataClient) Intercept(interceptors ...Interceptor) {
c.inters.ServerMetadata = append(c.inters.ServerMetadata, interceptors...)
}
// Create returns a builder for creating a ServerMetadata entity.
func (c *ServerMetadataClient) Create() *ServerMetadataCreate {
mutation := newServerMetadataMutation(c.config, OpCreate)
return &ServerMetadataCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of ServerMetadata entities.
func (c *ServerMetadataClient) CreateBulk(builders ...*ServerMetadataCreate) *ServerMetadataCreateBulk {
return &ServerMetadataCreateBulk{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 *ServerMetadataClient) MapCreateBulk(slice any, setFunc func(*ServerMetadataCreate, int)) *ServerMetadataCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &ServerMetadataCreateBulk{err: fmt.Errorf("calling to ServerMetadataClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*ServerMetadataCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &ServerMetadataCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for ServerMetadata.
func (c *ServerMetadataClient) Update() *ServerMetadataUpdate {
mutation := newServerMetadataMutation(c.config, OpUpdate)
return &ServerMetadataUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *ServerMetadataClient) UpdateOne(sm *ServerMetadata) *ServerMetadataUpdateOne {
mutation := newServerMetadataMutation(c.config, OpUpdateOne, withServerMetadata(sm))
return &ServerMetadataUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *ServerMetadataClient) UpdateOneID(id uuid.UUID) *ServerMetadataUpdateOne {
mutation := newServerMetadataMutation(c.config, OpUpdateOne, withServerMetadataID(id))
return &ServerMetadataUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for ServerMetadata.
func (c *ServerMetadataClient) Delete() *ServerMetadataDelete {
mutation := newServerMetadataMutation(c.config, OpDelete)
return &ServerMetadataDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *ServerMetadataClient) DeleteOne(sm *ServerMetadata) *ServerMetadataDeleteOne {
return c.DeleteOneID(sm.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *ServerMetadataClient) DeleteOneID(id uuid.UUID) *ServerMetadataDeleteOne {
builder := c.Delete().Where(servermetadata.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &ServerMetadataDeleteOne{builder}
}
// Query returns a query builder for ServerMetadata.
func (c *ServerMetadataClient) Query() *ServerMetadataQuery {
return &ServerMetadataQuery{
config: c.config,
ctx: &QueryContext{Type: TypeServerMetadata},
inters: c.Interceptors(),
}
}
// Get returns a ServerMetadata entity by its id.
func (c *ServerMetadataClient) Get(ctx context.Context, id uuid.UUID) (*ServerMetadata, error) {
return c.Query().Where(servermetadata.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *ServerMetadataClient) GetX(ctx context.Context, id uuid.UUID) *ServerMetadata {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryFollower queries the follower edge of a ServerMetadata.
func (c *ServerMetadataClient) QueryFollower(sm *ServerMetadata) *UserQuery {
query := (&UserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := sm.ID
step := sqlgraph.NewStep(
sqlgraph.From(servermetadata.Table, servermetadata.FieldID, id),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, servermetadata.FollowerTable, servermetadata.FollowerColumn),
)
fromV = sqlgraph.Neighbors(sm.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryFollowee queries the followee edge of a ServerMetadata.
func (c *ServerMetadataClient) QueryFollowee(sm *ServerMetadata) *UserQuery {
query := (&UserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := sm.ID
step := sqlgraph.NewStep(
sqlgraph.From(servermetadata.Table, servermetadata.FieldID, id),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, servermetadata.FolloweeTable, servermetadata.FolloweeColumn),
)
fromV = sqlgraph.Neighbors(sm.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *ServerMetadataClient) Hooks() []Hook {
return c.hooks.ServerMetadata
}
// Interceptors returns the client interceptors.
func (c *ServerMetadataClient) Interceptors() []Interceptor {
return c.inters.ServerMetadata
}
func (c *ServerMetadataClient) mutate(ctx context.Context, m *ServerMetadataMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&ServerMetadataCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&ServerMetadataUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&ServerMetadataUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&ServerMetadataDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown ServerMetadata 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 uuid.UUID) *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 uuid.UUID) *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 uuid.UUID) (*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 uuid.UUID) *User {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryAvatarImage queries the avatarImage edge of a User.
func (c *UserClient) QueryAvatarImage(u *User) *ImageQuery {
query := (&ImageClient{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(image.Table, image.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, user.AvatarImageTable, user.AvatarImageColumn),
)
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryHeaderImage queries the headerImage edge of a User.
func (c *UserClient) QueryHeaderImage(u *User) *ImageQuery {
query := (&ImageClient{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(image.Table, image.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, user.HeaderImageTable, user.HeaderImageColumn),
)
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryAuthoredNotes queries the authoredNotes edge of a User.
func (c *UserClient) QueryAuthoredNotes(u *User) *NoteQuery {
query := (&NoteClient{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(note.Table, note.FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, user.AuthoredNotesTable, user.AuthoredNotesColumn),
)
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryMentionedNotes queries the mentionedNotes edge of a User.
func (c *UserClient) QueryMentionedNotes(u *User) *NoteQuery {
query := (&NoteClient{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(note.Table, note.FieldID),
sqlgraph.Edge(sqlgraph.M2M, true, user.MentionedNotesTable, user.MentionedNotesPrimaryKey...),
)
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 {
Attachment, Follow, Image, Note, ServerMetadata, User []ent.Hook
}
inters struct {
Attachment, Follow, Image, Note, ServerMetadata, User []ent.Interceptor
}
)